#include <sys/reboot.h>

#include <algorithm>
#include <sstream>
#include <regex>
#include <fstream>
#include <tinyxml.h>

#include "cconffile.h"
#include "ql_oe.h"
#include "ql_wifi.h"
#include "defines.hpp"
#include "at.hpp"
#include "misc.h"
#include "timer.hpp"
#include "ary_str.hpp"
#include "dtu.hpp"
#include "gps.hpp"
#include "../version.h"
#include "dial.hpp"
#include "base64.hpp"
#include "serial.hpp"
#include "sms.hpp"
#include "smsio.hpp"
#include "config.hpp"
#include "devM.hpp"
#if defined( __USE_MEMPOOL__)
#   include <jemalloc/jemalloc.h>
#endif

const bool atInst :: at_serial = true;
const bool atInst :: at_net    = false;

/**
 * @brief 设置APN
 * @param apn , APN接入点
 * @param usr , 
 * @param pswd 
 * @return 成功返回0；否则返回值小于0
 * @note 设置完成后必须重新启动操作系统
*/
int apn_set( const std::string& _apn , const std::string& usr , const std::string& pswd )
{
	if( _apn.empty() ) return -1;
	if( usr.empty() ) return -2;

	ql_apn_info_s apn;
	memset(&apn, 0, sizeof(apn));
	apn.profile_idx = 1;

	apn.pdp_type = QL_APN_PDP_TYPE_IPV4;

	strcpy(apn.apn_name, _apn.c_str());
	strcpy(apn.username, usr.c_str() );

	strcpy(apn.password, pswd.c_str() );


	if(QL_APN_Set(&apn)){ return -3; }

	return 0;
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
atInst :: stAtHash :: stAtHash( )
{
}

atInst :: stAtHash :: stAtHash( const std::string& reg , const std::string& desc, const std::string& msg )
{
	reg_str = reg;
	fun_desc = desc;
	err_msg = msg;
}

atInst :: stAtHash :: stAtHash( const stAtHash& b )
{
	reg_str = b.reg_str;
	fun_desc = b.fun_desc;
	err_msg = b.err_msg;

	fun = b.fun;
}

atInst :: stAtHash :: stAtHash( stAtHash && b )
{
	reg_str = std::move( b.reg_str );
	fun_desc = std::move( b.fun_desc );
	err_msg = std::move( b.err_msg );

	fun = b.fun;
}

atInst :: stAtHash &
atInst :: stAtHash :: operator=( stAtHash&& b )
{
	reg_str = std::move( b.reg_str );
	fun_desc = std::move( b.fun_desc );
	err_msg = std::move( b.err_msg );

	fun = b.fun;
	return *this;
}

atInst :: stAtHash &
atInst :: stAtHash :: operator=( const stAtHash& b )
{
	reg_str = b.reg_str;
	fun_desc = b.fun_desc ;
	err_msg = b.err_msg;

	fun = b.fun;
	return *this;
}


atInst :: stAtHash :: operator bool()
{
	if( fun )
		return true;
	return false;
}

atInst::stAtHash::~stAtHash()
{
}
// ====================================================================================================
atCom * atCom :: ptSerialAT = nullptr;

atInst::atInst( filterList *l , bool atType )
: filterIO( filterIO::tail , l )
{
	__show_line_1("%s" , "\tStart AT Command Engine..." );
	
	AT_OK_STR = "\r\nOK\r\n";
	m_at_type = atType;
#if ENABLE_PHY == 1 || ENABLE_WIFI == 1
	m_root_status = false;
#endif
	if( atType == at_net )
		m_type = filterIO::head;
	m_status = status::TRANS;
	m_echo = true;
	std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
	if( ptvar ){
		ptvar->GetValue( "/at/passwd" , m_at_pswd );
	}else{
		m_at_pswd = "signal";
	}
	init_hash();

	std::cout << TGREEN <<  "[ OK ]" << TNORMAL << std::endl;
}

atInst::~atInst()
{
}


void atInst::init_hash()
{
	init_at();                   // AT
	init_h();                    // AT+H
	init_z();                    // AT+Z
	init_reboot();               // AT+REBOOT
	init_e();                    // AT+E
	init_entm();                 // AT+ENTM
	init_wkmod();                // AT+WKMOD
	init_cmdpw();                // AT+CMDPW
	init_stmsg();                // AT+STMSG
	init_csq();                  // AT+CSQ
	init_rstim();                // AT+RSTIM
	init_sysinfo();              // AT+SYSINFO
	init_ver();                  // AT+VER

	init_reld();                 // AT+RELD
	init_clear();                // AT+CLEAR
	init_cfgtf();                // AT+CFGTF

	init_ver();                  // AT+VER
	init_sn();                   // AT+SN
	init_iccid();                // AT+SN
	init_imei();                 // AT+IMEI

	init_uart();
	init_uartft();
	init_uartfl();
	init_rfcen();
	init_uartpk();

	init_apn();
	init_socka();
	init_sockb();
	init_sockc();
	init_sockd();
	init_sockaen();
	init_sockben();
	init_sockcen();
	init_sockden();
	init_sockasl();
	init_sockbsl();
	init_sockcsl();
	init_sockdsl();
	init_sockalk();
	init_sockblk();
	init_sockclk();
	init_sockdlk();
	init_shorato();
	init_shorbto();
	init_shorcto();
	init_shordto();
	init_sockato();
	init_sockbto();
	init_sockcto();
	init_sockdto();
	init_sockind();
	init_sdpen();

	init_regen();
	init_regen_a();
	init_regen_b();
	init_regen_c();
	init_regen_d();

	init_regtp();
	init_regtp_a();
	init_regtp_b();
	init_regtp_c();
	init_regtp_d();

	init_regsnd();
	init_regsnd_a();
	init_regsnd_b();
	init_regsnd_c();
	init_regsnd_d();

	init_regdt();
	init_regdt_a();
	init_regdt_b();
	init_regdt_c();
	init_regdt_d();

	init_cloud();

	init_hearten();
	init_hearten_a();
	init_hearten_b();
	init_hearten_c();
	init_hearten_d();
	
	init_heartdt();
	init_heartdt_a();
	init_heartdt_b();
	init_heartdt_c();
	init_heartdt_d();

	init_heartsnd();
	init_heartsnd_a();
	init_heartsnd_b();
	init_heartsnd_c();
	init_heartsnd_d();

	init_hearttm();
	init_hearttm_a();
	init_hearttm_b();
	init_hearttm_c();
	init_hearttm_d();

	init_htpen();
	init_htptp();
	init_htpurl();
	init_htpsv();
	init_htphd();
	init_htpto();
	init_htpflt();

	init_smsend();
	init_cismssend();

	init_hz();
	init_reset();
	init_sockadd();
	init_sock();
	init_sockdel();
	init_ping();
	init_ca();
	init_cer();
	init_mqttsvr();
	init_mqttuser();
	init_mqtttpc();
	init_mqttsnd();
	init_mqttunsub();

	init_kd();
	init_comd();
	init_netd();
	init_ssl();
	init_htps();
	init_crypto();
	init_zip();
	init_filter();
	init_report();
	init_rmset();
	init_rmta();
	init_save();
	init_gpsen();
	init_agps();
	init_gpsfreq();
	init_gpssv();
	init_gpsdat();
	init_gpsspeed();

	init_reghex_en();
	init_reghex_ena();
	init_reghex_enb();
	init_reghex_enc();
	init_reghex_end();

	init_heart_hex();
	init_heart_hexa();
	init_heart_hexb();
	init_heart_hexc();
	init_heart_hexd();
	init_autoreboot();
	init_fsnset();
#if ENABLE_WIFI == 1
	init_wifien();
	init_wifi();
	init_wificln();
#endif

#if ENABLE_PHY == 1
	init_phyen();
#endif

#if ENABLE_PHY == 1 || ENABLE_WIFI == 1
	init_lan();
	init_firewall();
	init_rootPswd();
	init_firelist();
	init_firemac();
	init_firesave();
#endif

#if ENABLE_MODBUS == 1
	init_modbus_en();
	init_mbadd();
	init_mbl();
	init_mbdel();
#endif
}

bool atInst::check_inst( const std::string& at_ , const std::string& cmd, atgHashIt_t& it )
{
	bool            ret = false;
	std::string  	at  = at_;
	if( at.find( "\r") == std::string::npos ){
		size_t pos = at.find("\n");
		if( pos != std::string::npos )
		at.insert( pos , "\r");
	}
	
	ret = check_gramma( at , cmd , it );

	return ret;
}

bool atInst::check_gramma( const std::string& at , const std::string& cmd , atgHashIt_t & it )
{
	bool   ret = false;

	it = m_at_hash.find( cmd );
	if( it != m_at_hash.end() ){
		std::regex    reg( it->second.reg_str , std::regex_constants::icase);

		ret = std::regex_search( at , reg  );
		if( ret == false ){
				std::stringstream err;
				std::string       err_str;

				err << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n"
					<< "Bad AT Command gramma" << "\r\n";
				err_str = std::move( err.str() );

			if( m_at_type == atInst :: at_serial ){
				backward(  ptList[ 0 ]->rbegin() , err_str.length() , err_str.c_str() , OK );
			}
			else if( m_at_type == atInst :: at_net ){
				forward( ptList[ 0 ]->begin() , err_str.length() , err_str.c_str() , OK );
			}
		}
	}else{
		//指令不支持
		ret = false;
		m_at_error = ERR_UNSUPORTED_INST;

		std::stringstream err;
		std::string       err_str;

		err << "\r\n+ERR:" << m_at_error << "\r\n"
		<< "Unsupported AT Command" << "\r\n";
		err_str = std::move( err.str() );

		if( m_at_type == atInst :: at_serial ){
			backward(  ptList[ 0 ]->rbegin() , err_str.length() , err_str.c_str() , OK );
		}
		else if( m_at_type == atInst :: at_net ){
			forward( ptList[ 0 ]->begin() , err_str.length() , err_str.c_str() , OK );
		}
	}
	return ret;
}

bool atInst::real_split( const std::string& at , const std::string& cmd , ArrayString& params  )
{
	std::string   tmp_str = at.substr( cmd.length() , at.length() );

	std::regex  reg( "(?=|\\,)\"{0,1}(\\w|[-'@\"\\%\\#\\*\\^\\&\\!\\$\\/\\\\<>\\.\\?\\s:]|[\\x80-\\xff])+\"{0,1}");     // 匹配参数
	std::smatch sm;
	while( tmp_str.empty() == false ){
		if( std::regex_search( tmp_str , sm , reg ) ){
			std::string str = std::move( sm[ 0 ] );
			size_t pos = str.find( "\n");
			
			if( pos >= 0 && pos != std::string::npos )
				str = str.replace( pos , 1 , "" );								// 过滤掉换行符
			
			pos = str.find( "\r");
			
			if( pos >= 0 && pos != std::string::npos )
				str = str.replace( pos , 1 , "" );                              // 过滤掉回车符
			params.push_back( str );
			tmp_str = std::move( sm.suffix() );                                 // 必须支持C++ 11
		}
	}

	return true;
}

bool atInst::split( const std::string& __at , std::string& cmd , ArrayString& params )
{
	bool ret = false;
	std::string  at = __at;

	if( at.find( "\r") == std::string::npos ){  // 如果找不到回车符号，则再换行符号前面添加回车符号
		size_t pos = at.find( "\n");
		if( pos != std::string::npos )
		at.insert( pos , "\r"  );
	}
	size_t  eq_pos = at.find( "=" );
	if( eq_pos != std::string::npos )
		cmd = at.substr( 0 , eq_pos );
	else{
		cmd = at.substr( 0 , at.find("\r"));
	}
	std::transform( cmd.begin() , cmd.end() , cmd.begin() , ::toupper );
	size_t  at_pos = cmd.find("AT");         // 找出AT避免在AT前还有其他异常字符

	if( at_pos == 0 ){
		if( eq_pos != std::string::npos ){ // 有参数的指令,将参数分割开来
			ret = real_split( at , cmd , params );
		}else{// 无参数的指令
			params.erase( params.begin() , params.end() );
			eq_pos = at.find( "\r" );
			std::regex reg( "AT\\+\\w+" );
			std::smatch sm;
			if( std::regex_search( cmd , sm ,reg ) ){
				__show_line_2();
				cmd = sm[ 0 ];
				ret = true;
			}else if( at.find("AT\r") != std::string::npos ){// 检查AT指令是否响应的指令AT
				__show_line_2();
				std::string str = AT_OK_STR;
				response( at , str );
			}else{
				__show_line_2();
				ret = false;
				bad_at_start();
			}
		}
	}else{
		ret = false;
		bad_at_start();
	}
	return ret;
}

void atInst :: bad_at_start()
{
	m_at_error = ERR_BAD_AT_START;
	std::stringstream err;
	std::string       err_str;

	err << "\r\n+ERR:" << m_at_error << "\r\n" << "Wrong AT Command Start.\r\n";
	err_str = std::move( err.str() );
	if( m_at_type == atInst :: at_serial ){
		backward(  ptList[ 0 ]->rbegin() , err_str.length() , err_str.c_str() , OK );
	}
	else if( m_at_type == atInst :: at_net ){
		forward( ptList[ 0 ]->begin() , err_str.length() , err_str.c_str() , OK );
	}
}
void atInst::real_process_at( const std::string& cmd , const std::string& at , const ArrayString& params )
{
	atgHashIt_t it = m_at_hash.find( at );
	if( check_inst( cmd , at ,it ) == true ){
		if( it != m_at_hash.end() ){
			it->second.fun( cmd , params );
		}
	}
}

void atInst::process_at_serial( const std::string& cmd )
{
    	if( m_status == status::TRANS ){// 检查状态
        	__show_line_1( "%s%s%s" , TYELLOW , "AT Serial" , TNORMAL );
		// 透传状态
        	if( cmd == "+++"){
            		dtu * dev = GetOrCreateDTU();
            		if( dev ) dev->PauseModbus();             // 停止MODBUS自动采集任务，避免和AT指令冲突

            		m_status = status::HANDSHAKEING;
            		backward(  ptList[ 0 ]->rbegin() , 1 , "a" , OK );

            		// 启动握手超时计时器，如果握手反馈超时。状态转换到透传状态
           		m_handshake_overtime.SetOwner( [ this ]{
                		m_status = status::TRANS;
                 		// 恢复modbus运行
                 		dtu * dev = GetOrCreateDTU();
                 		if( dev ) dev->RestoreModbus();
            		});
            		m_handshake_overtime.Start( 10000 , true );// 10s握手超时
        	}else if( cmd.find("#AT") != std::string::npos ){
			// 透传模式下使用 密码#AT 执行AT指令
			__show_line_1( "%s%s%s" , TYELLOW , "Serial DIRECT AT command is called" , TNORMAL );
		
			process_at_pswd( cmd );
		}
   	}else if( m_status == status::HANDSHAKEING ){      // 握手状态
       		if( cmd == "a" ){
            		m_status = status::AT;
			backward(  ptList[ 0 ]->rbegin() , 2 , "ok" , OK );
			m_status = status::AT;
            		m_handshake_overtime.Stop();
        	}else{  
			m_status = status::TRANS; 
		}
    	}else{                                            // AT指令状态
        	std::string at;       
		ArrayString params;
		if( split( cmd , at , params ) == true ){
            		real_process_at( cmd , at , params );
        	}
    	}
}

void atInst:: process_at_pswd( const std::string& cmd_str )
{
	// 检查指令密码
	std::string at , cmd , pswd;       ArrayString params;

	size_t pos = cmd_str.find("#AT");
	if( pos == std::string::npos ){ // 如果没有 #AT+, 说明是普通数据
		return;
	}

	pswd = cmd_str.substr( 0 , pos );		// 摘取密码
	if( pswd == m_at_pswd ){
		cmd = cmd_str.substr( pos + 1 , cmd_str.length() );
    	if( split( cmd , at , params ) == true ){
        	real_process_at( cmd , at , params );
    	}
	}else{
		std::stringstream  ss;
		ss << "+ERR:" << ERR_BAD_PASWD << "\r\nBad password.\r\n";
		std::string str = std::move( ss.str());
		if( m_at_type == atInst :: at_serial ){
			backward(  ptList[ 0 ]->rbegin() , str.length() , str.c_str() , OK );
		}
		else if( m_at_type == atInst :: at_net ){
			forward( ptList[ 0 ]->begin() , str.length() , str.c_str() , OK );
		}
	}
}

bool atInst::on_forward( size_t len , const char * data , err_code &err , size_t& rlen , char ** rd )
{
	if( m_at_type == atInst::at_serial ){
		char * tmp_data = (char *)malloc( len + 1 );
		std::string   cmd;
		if( tmp_data ){
			memcpy( tmp_data , data , len );
			tmp_data[ len ] = 0;
			cmd = std::move( tmp_data );
		}
		if(  ( m_status == status::TRANS ) && ( cmd != "+++" ) && cmd.find("#AT") == std::string::npos  ){
			*rd = ( char*) data;
			rlen = len;
			return false;
		}
    		// 将数据转换成大写字符, 这样设备就能够支持大小写无区别的AT指令
    		//std::transform( cmd.begin() , cmd.end() , cmd.begin() , (int(*)(int))std::toupper );
        	process_at_serial( cmd );

		*rd = (char*)data;
		rlen = len;
    		return false;
	}else if( m_at_type == atInst :: at_net ){
		*rd = (char*)data;
		rlen = len;
		return true;
	}

	return true;
}

bool atInst::on_backward( size_t len , const char * data , err_code &err , size_t& rlen , char ** rd  )
{
    	if( data == nullptr ) return false;
    	if( len == 0        ) return false;

	rlen = len;
	*rd = ( char *)data;

	if( m_at_type == atInst :: at_serial ){
		return true;
	}else if( m_at_type == atInst :: at_net ){
		std::string str;
	    //__show_line_1( "%s%s%s%s" , TYELLOW , "AT Module get data : " , TBLUE , data );
		char * __data = ( char *)malloc( len + 1 );
		if( __data ){
			memcpy( __data , data , len );
			__data[ len ] = ( char )0;

			str = std::move( __data );
			process_at_pswd( str );
		}else{
			std::cout << "Alloc memory fail" << std::endl;
			abort();
		}

		return false;
	}

	return false;
}
/*
 **********************************************************************************************************
 **** 以上内容是AT指令引擎代码
 **** 以下内容AT指令执行操作的内容
 **********************************************************************************************************
*/

void atInst :: response( const std::string& echo , const std::string& res )
{
	/* 指令回显。如果打开程序首先会将接受的AT指令回显到接口 */
    	std::string  str;
	if( m_echo ){
        	str = echo + res;
	}else{ 
		str = res;
	}

	if( m_at_type == atInst :: at_serial ){
       		backward(  ptList[ 0 ]->rbegin() , str.length() , str.c_str() , OK );
	}
	else if( m_at_type == atInst :: at_net ){
		forward( ptList[ 0 ]->begin() , str.length() , str.c_str() , OK );
	}
}

void atInst::init_at()
{
    	stAtHash  item( "AT\\r" , "Check If AT command response OK." , "AT<RET>" );
    	item.fun = [this]( const std::string& at , const ArrayString& params ){

        	std::string str = "\r\nOK\r\n";

        	if( params.size() > 0 ){
            		std::stringstream ss;
            		ss << "\r\n" << ERR_BAD_GRAMMA << "\r\n"
			   << "[FUNCTION]:" << m_at_hash["AT"].fun_desc << "\r\n"
			   << "[GRAMMA]:" << m_at_hash["AT"].err_msg << "\r\n";

            		str = std::move( ss.str() );
        	}

       	 	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT" , item ));
}

void atInst::init_h()
{
    	stAtHash  item( "AT\\+H\\r" , "Show AT Command Help text." , "AT+H<RET>" );
    	item.fun = [this](const std::string& at ,  const ArrayString& params ){
		std::string str = "\r\nOK\r\n";

		std::ifstream is( "/data/etc/dtu/help.txt" );
		if( is.is_open() == true ){
			while( is.eof() == false ){
				std::string tmp_str;
				std::getline( is , tmp_str );
				str = str + tmp_str + "\n";
			}
		}else{
			std::stringstream ss;
			ss << "\r\n+ERR:" << ERR_CAN_NOT_FIND_HELP_FILE << "\r\n"
					<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
					<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
			str = ss.str();
		}

		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+H" , item ));
}

void atInst::init_z()
{
	stAtHash  item( "AT\\+Z\\r" , "Restart DTU Service." , "AT+Z<RET>" );
	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str = "\r\nOK\r\n";
		response( at , str );

		abort();       // 退出程序执行
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+Z" , item ));
}


void atInst::init_reboot()
{
	stAtHash  item( "AT\\+REBOOT\\r" , "Reboot Device." , "AT+REBOOT<RET>" );
	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str = "\r\nOK\r\nSystem will restart , this will be in 40s.";
		response( at , str );

		// 重启模块。因为直接调用重启操作。会导致配置文件丢失，随意尝试使用这个方式
		// 先退出主程序，更新配置文件然后在重启系统。
		int pid = fork();
		if( pid < 0 ){
			std::cout << "Start new process fail." << std::endl;
		}else if( pid == 0 ){ // 子进程，1s以后调用重启程序
			sync();
			sleep( 5 );
			reboot( RB_AUTOBOOT ) ;
		}else{ // 退出主程序
			system("killall dog");
			abort();
		}

	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REBOOT" , item ));
}

void atInst::init_e()
{
	std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
	bool en = true;
	if( ptvar )
		ptvar->GetValue( "/echo_en" , en );
	m_echo = en;
    	stAtHash  item( "AT\\+E((\\?{0,1}\\r)|(\\=(ON|OFF)\\r))" ,
                    "Check echo status OR Enable/Disable AT echo." ,
                    "AT+E[?]<RET> check echo status\n AT+E=(ON|OFF) Enable Or Disable Echo" );
    	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str = "\r\nOK\r\n";
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( params.size() > 0 ){ // 执行设置指令
			if( params[ 0 ] == "ON"){
				m_echo = true;
				if( ptvar )
					ptvar->SetValue( "/echo_en" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ] == "OFF" ){
				m_echo = false;
				ptvar->SetValue( "/echo_en" , false );
				str = AT_OK_STR;
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n"
				<<"Unsupported parameter(s)\r\n"
				<<"[FUNCTION]:" << m_at_hash[""].fun_desc
				<<"[GRAMMA]:" << m_at_hash[""].err_msg << "\r\n";
			}
		}else{  // 执行查询指令
			std::stringstream ss;
			ss << "\r\nOK\r\n+E:";

			// 设置回显查询
			if( m_echo )  ss << "ON\r\n";
			else ss << "OFF\r\n";

			str = std::move( ss.str());
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+E" , item ));
}

void atInst::init_autoreboot()
{
	stAtHash  item( "AT\\+ABOOT(\\?|=(ON|OFF)\\,(\\d{1,5})){0,1}\\r" , "Set autoreboot params." , "AT+ABOOT<RET>" );
    	item.fun = [this](const std::string& at ,  const ArrayString& params ){
		std::shared_ptr< CSysVar > 	ptvar = GetOrCreateSysVar();
		std::string 			str;
		std::stringstream 		ss;
		if( params.size() == 2 ){ // 执行设置
			if( params[ 0 ] == "ON" ){
				ptvar->SetValue( "/auto_boot/enable" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ] == "OFF" ){
				ptvar->SetValue( "/auto_boot/enable" , false );
				str = AT_OK_STR;
			}else{
				ss << "+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
                		str = std::move( ss.str() );
			}

			long len;
			
			ss << params[ 1 ];
			ss >> len;

			ptvar->SetValue( "/auto_boot/time" , len );
		}else if( params.size() == 0 ){ // 执行读取
			
			bool en = false;
			ptvar->GetValue( "/auto_boot/enable" , en );
			long time = 0;
			ptvar->GetValue( "/auto_boot/time" , time );

			ss << "\r\nOK\r\n+ABOOT:" << ( en ? "ON," : "OFF," ) << time << "\r\n";
			str = std::move( ss.str() );
		}else{// 指令错误
			ss << "+ERR:" << ERR_BAD_PARAM << "\r\n";
                	str = std::move( ss.str() );
		}
		
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+ABOOT" , item ));
}

void atInst::init_entm()
{
	stAtHash  item( "AT\\+ENTM\\r" , "Switch to transparent transmission." , "AT+ENTM<RET>" );
	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str = "\r\nOK\r\n";

		std::thread thd([ this ]{
			std::this_thread::yield();
			std::this_thread::sleep_for( std::chrono::milliseconds( 500 ));
			m_status = status::TRANS;
		});
		thd.detach();

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+ENTM" , item ));
}

void atInst::init_wkmod()
{
    	stAtHash  item( "AT\\+WKMOD(\\?|\\=(NET|HTTPD|SMS)){0,1}\\r" ,
                    "Query or Set device Working mode." ,
                    "AT+WKMOD[?]<RET> query woking mode. AT+WKMOD=(NET|HTTPD|SMS)<RET> set woking mode." );
    	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string       str = "\r\nOK\r\n";
        	std::stringstream ss;
		dtu * ptdtu = GetOrCreateDTU();
		if( ptdtu == nullptr ){
            		std::cout << TRED << "[[ ERROR ]]:" <<TNORMAL << " 找不到DTU模块。" << std::endl;
            		abort();
            		return;
		}

    		if( params.size() > 0 ){        // 执行设置指令
            		dtu :: err_code e;
            		e = ptdtu->WKMOD( params[ 0 ] );
            		if( e == dtu :: OK ){
                		str = AT_OK_STR;
            		}else if( e == dtu :: ERR_WKMOD_NOT_SUPPORTED ){
                		ss << "+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n"
                		<< "Unsupported paramter(s)."
                		<< "[FUNCTION]:" << m_at_hash["AT+WKMOD"].fun_desc << "\r\n"
                		<< "[GRAMMA]:" << m_at_hash[ "AT+WKMOD" ] << "\r\n";
                		str = std::move( ss.str() );
            		}else if( e == dtu :: ERR_CONF_OBJ ){
                		ss << "+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n"
                		<< "System Error."
                		<< "[FUNCTION]:" << m_at_hash["AT+WKMOD"].fun_desc << "\r\n"
                		<< "[GRAMMA]:" << m_at_hash[ "AT+WKMOD" ] << "\r\n";
                		str = std::move( ss.str() );
            		}else{
                		ss << "+ERR:" << ERR_UNKNOWN << "\r\n"
                		<< "System Error."
                		<< "[FUNCTION]:" << m_at_hash["AT+WKMOD"].fun_desc << "\r\n"
                		<< "[GRAMMA]:" << m_at_hash[ "AT+WKMOD" ] << "\r\n";
                		str = std::move( ss.str() );
            		}
    		}else{                          // 执行查询指令
        		str = str + "\r\n+WKMOD:";
        		switch( GetOrCreateDTU()->WKMOD() ){
				case dtu::NET:     str = str + "NET";               break;
				case dtu::HTTPD:   str = str + "HTTPD";             break;
				case dtu::WK_MQTT: str = str + "MQTT";              break;
				case dtu::TCPSSL:  str = str + "TCPSSL";            break;
				case dtu::MQTTSSL: str = str + "MQTTSSL";           break;
	   			case dtu::HTTPS:   str = str + "HTTPS";    	    break;
	   			default:
					ss << "+ERR:" << ERR_SYS_ERROR << "\r\n"
					<< "System Error."
					<< "[FUNCTION]:" << m_at_hash["AT+WKMOD"].fun_desc << "\r\n"
					<< "[GRAMMA]:" << m_at_hash[ "AT+WKMOD" ] << "\r\n";
            				str = std::move( ss.str() );
					
				return;
        		}

        		str = str + "\r\n";
    		}
       	 	response( at , str );
        
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+WKMOD" , item ));
}

void atInst::init_cmdpw()
{// 命令密码 ， 主要用于SMS和网络AT指令
    	stAtHash  item( "AT\\+CMDPW(\\?|=(\\w|-|_|%|&|\\*|\\$|@|\\.){1,10}){0,1}\\r" ,
                    "Query or Set net AT command password" ,
                    "AT+CMDPW[?]<RET> query password\n AT+CMDPW=\"[alphabet or digit max length 10]\" set password" );
    	item.fun = [this]( const std::string& at , const ArrayString& params ){
		dtu * ptdtu = GetOrCreateDTU();
        	std::string str;
       	 	if( ptdtu ){
			if( params.size() > 0 ){   // 设置密码
				std::stringstream ss;
				str = params[ 0 ];
				dtu :: err_code e = ptdtu->ATPswd( str );
				if( e == dtu :: ERR_CONF_OBJ ){
				ss << "+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n"
				<< "System Error."
				<< "[FUNCTION]:" << m_at_hash["AT+CMDPW"].fun_desc << "\r\n"
				<< "[GRAMMA]:" << m_at_hash[ "AT+CMDPW" ] << "\r\n";
				}else if( e == dtu :: OK ){
				ss << AT_OK_STR;
				}else{
				ss << "+ERR:" << ERR_UNKNOWN << "\r\n"
				<< "System Error."
				<< "[FUNCTION]:" << m_at_hash["AT+CMDPW"].fun_desc << "\r\n"
				<< "[GRAMMA]:" << m_at_hash[ "AT+CMDPW" ] << "\r\n";
				}

				str = std::move( ss.str() );
			}else{  // 读取密码
				str = AT_OK_STR + "+CMDPW:" + ptdtu->ATPswd() + "\r\n";
			}
		}else{
			std::stringstream ss;
			ss << "+ERR:" << ERR_SYS_ERROR << "\r\n"
			<< "System Error."
			<< "[FUNCTION]:" << m_at_hash["AT+CMDPW"].fun_desc << "\r\n"
			<< "[GRAMMA]:" << m_at_hash[ "AT+CMDPW" ] << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CMDPW" , item ));
}

void atInst::init_stmsg()
{
    stAtHash  item("AT\\+STMSG(\\?|=(\\w|\\W){0,20}){0,1}\\r" ,
                   "Get or set start message" ,
                   "AT+STMSG[?]<RET> query device start message. \nAT+STMSG=\"(message data)\"<RET> set device start message" );

    	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string   str=AT_OK_STR;
		std::stringstream ss;
			
		dtu * ptdtu = GetOrCreateDTU();
		if( ptdtu ){
		if( params.size() > 0 ){ // 设置指令
			std::string msg = params[ 0 ];
			msg = msg.substr( msg.find( "\"" ) + 1 , msg.length() );
			msg = msg.substr( 0 , msg.find( "\"" ) );
			dtu::err_code e = ptdtu->StartMsg( msg );
			if( e == dtu :: OK ){
				str = AT_OK_STR;
			}else if( e == dtu :: ERR_CONF_OBJ ){
				ss << "\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n"
				<< "System Error."
				<< "[FUNCTION]:" << m_at_hash["AT+CMDPW"].fun_desc << "\r\n"
				<< "[GRAMMA]:" << m_at_hash[ "AT+CMDPW" ] << "\r\n";
				str = ss.str();
			}else{
				ss << "\n+ERR:" << ERR_SYS_ERROR << "\r\n"
					<< "System Error."
				<< "[FUNCTION]:" << m_at_hash["AT+CMDPW"].fun_desc << "\r\n"
				<< "[GRAMMA]:" << m_at_hash[ "AT+CMDPW" ] << "\r\n";
				str = ss.str();
			}
		}else{                   // 查询指令
			str = ptdtu->StartMsg( );
			str = AT_OK_STR + "+STMSG:" + str + "\r\n";
		}
		}else{
			std::stringstream ss;
			ss << "\r\n+ERR:" << ERR_SYS_ERROR << "\r\n"
			<< "System Error."
			<< "[FUNCTION]:" << m_at_hash["AT+CMDPW"].fun_desc << "\r\n"
			<< "[GRAMMA]:" << m_at_hash[ "AT+CMDPW" ] << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+STMSG" , item ) );
}

void atInst::init_rstim()
{
    	stAtHash  item("AT\\+RSTIM(\\?|=\\d+){0,1}\\r" ,
                   "Get Or set device auto restart time, unit second." ,
                   "AT+RSTIM[?]<RET> get restart time\nAT+RSTIM=(time) set restart time" );

    	item.fun = [this](const std::string& at , const ArrayString& params ){

		std::string str;
		std::stringstream ss;
		dtu * ptdtu = GetOrCreateDTU();
		if( ptdtu ){
			if( params.size() > 0 ){
				long itval = 30;
				std::regex reg("\\d+");
				std::string tmp = params[ 0 ];
				tmp = tmp.substr( 0 , tmp.find("\r") );
				if( std::regex_search( tmp , reg ) == false ){
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n"
					<< "Wrong Gramma\r\n"
					<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
					<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
					str = ss.str();
                		}else{
					ss << tmp;
					ss >> itval;
					ss.clear(); ss.str("");
					dtu :: err_code e = ptdtu->RestartIntval( itval );
					if( e == dtu :: OK ){
						str = AT_OK_STR;
					}else if( e == dtu::ERR_CONF_OBJ ){
                        			ss << "\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n"
						<< "Can not find system setting variable.\r\n"
						<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
 					    	<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
                        			str = ss.str();
                    			}else{
                        			ss << "\n+ERR:" << ERR_SYS_ERROR << "\r\n"
						<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
 					    	<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
                        			str = ss.str();
                    			}
                		}
            		}else{
                		long d = ptdtu->RestartIntval();
				ss << AT_OK_STR << "+RSTIM:" << d << "\r\n";
				str = ss.str();
            		}
        	}else{
            		ss<<"\r\n+ERR:" << ERR_SYS_ERROR << "\r\n"
			<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
			<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
            		str = ss.str();
        	}
        	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+RSTIM" , item ));
}

void atInst::init_csq()
{
    // 语法检查的正则表达式， 功能描述 ，错误提示信息
    	stAtHash  item("AT\\+CSQ\\?{0,1}\\r" , "Check Radio signal." , "AT+CSQ[?]<RET>" );

   	item.fun = [this](const std::string& at , const ArrayString& params ){
        	std::string str;
        	std::stringstream ss;
        	if( params.size() > 0 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n"
			<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
			<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
            		str = ss.str();
        	}else{
            		int csq = 0, e = 0;
           		 e = QL_NW_GetCSQ( &csq );
            		if( e == 0 ){
			    	ss << AT_OK_STR << "+CSQ:" << csq << ",99\r\n";
                		str = ss.str();
            		}else{
		        	ss << "\r\n+ERR:" << ERR_REQ_CSQ << "\r\n"
				<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
				<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
               	 		str = ss.str();
            		}
        	}
        	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CSQ" , item ));
}

void atInst::init_sysinfo()
{
    	// 查询设备网络信息
    	stAtHash  item("AT\\+SYSINFO\\?{0,1}\\r" , "Get Device network info." , "AT+SYSINFO[?]<RET>" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		if( params.size() != 0 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			ec20dial::sim_type  type = ec20dial::check_radio();
			std::string n;
			switch ( type ) {
				case ec20dial::_2G: n = "2G"; break;
				case ec20dial::_3G: n = "3G"; break;
				case ec20dial::_4G: n = "4G"; break;
				case ec20dial::__NW_UNKNOWN:
				default:
					n = "No Network";
				break;
			}
            		ss << AT_OK_STR << "+SYSINFO:" << n << "\r\n";
            		str = std::move( ss.str() );
        	}
        	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SYSINFO" , item) );
}

void atInst::init_reld()
{
    // 恢复出厂默认
	stAtHash  item("AT\\+RELD\\r" , "Restore user default settings." , "AT+RELD[?]<RET>" );

	item.fun = [this]( const std::string& at , const ArrayString& params ){

		std::string str;
		if( params.size() != 0 ){
			std::stringstream ss;
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
            		__show_line( "reload at inst is recved." );
			system("cp /data/etc/dtu/config.xml /data/sndtu/config.xml");
			/* 指令回显。如果打开程序首先会将接受的AT指令回显到接口 */
		    	if( m_echo ){
				if( m_at_type == atInst :: at_serial ){
		        		backward(  ptList[ 0 ]->rbegin() , at.length() , at.c_str() , OK );
				}
				else if( m_at_type == atInst :: at_net ){
					forward( ptList[ 0 ]->begin() , at.length() , at.c_str() , OK );
				}
			}
            		str = AT_OK_STR + "System will restart\r\n";
            		response( at , str );
			// 更新后重新启动应用程序
            		sync();
            		abort();
        	}
        	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+RELD" , item ) );
}
void atInst::init_clear()
{
	stAtHash  item("AT\\+CLEAR\\r" , "Restore producer settings" , "AT+CLEAR[?]<RET>" );

	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str;
		if( params.size() != 0 ){
			std::stringstream ss;
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			str = AT_OK_STR + "System will restart";
			response( at , str );

			system("cp /data/etc/dtu/usr-config.xml /data/sndtu/config.xml");
			//sleep( 1 );
			abort();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CLEAR" , item ));
}
void atInst::init_cfgtf()
{
	// 语法检查的正则表达式， 功能描述 ，错误提示信息
	stAtHash  item("AT\\+CFGTF\\r" , "Save current settings to user default." , "AT+CFGTF<RET>" );

	item.fun = [this]( const std::string& at , const ArrayString& params ){

		std::string str;
		if( params.size() > 0 ){
			std::stringstream ss;
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			str = AT_OK_STR;
			system("cp /data/sndtu/config.xml /data/etc/dtu/usr-config.xml");
			sync();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CFGTF" , item ) );
}

void atInst::init_ver()
{
	// 语法检查的正则表达式， 功能描述 ，错误提示信息
	stAtHash  item("AT\\+VER\\?{0,1}\\r" , "Get software version" , "AT+VER[?]<RET>" );

	item.fun = [this]( const std::string& at , const ArrayString& params ){
			
		std::string str;
		std::stringstream ss;
		if( params.size() != 0 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			ss << AT_OK_STR << "+VER:" << AutoVersion::FULLVERSION_STRING << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+VER" , item) );
}

void atInst::init_fsnset()
{
    // 语法检查的正则表达式， 功能描述 ，错误提示信息
    	stAtHash  item("AT\\+FSNSET=[0-9A-F]{16}\\r" , "Set device serial number." , "AT+SN=[SN]<RET>" );

    	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		
		if( ptvar ){
            		if( params.size() == 1 ){ // 设置SN
				ptvar->SetValue( "/SN" , params[ 0 ] );
				__show_line_2();
				CConfFile::err_code e = ptvar->Save( "/data/sndtu/config.xml" );
				if( e == CConfFile::OK ){
                    			__show_line_2();
                    			int e = system( "cp /data/sndtu/config.xml /data/etc/dtu" );
                    			system( "cp /data/sndtu/config.xml /data/etc/dtu/usr-config.xml" );
                    			if( e == 0 ){
						__show_line_2();
						str = AT_OK_STR;
						response( at , str );
						sleep( 5 );
						abort();
                    			}else{
						__show_line_2();
						ss << "\r\n+ERR:" << ERR_SET_SN_COPY << "\r\n";
						str = std::move( ss.str() );
                    			}
                		}else{
					ss << "\r\n+ERR:" << ERR_SET_SN_SAVE << "\r\n";
					str = std::move( ss.str() );
                		}
            		}else{
				ss << "\r\n+ERR:" << ERR_SET_SN << "\r\n";
				str = std::move( ss.str() );
            		}
        	}else{
            		ss<<"\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
            		str = ss.str();
        	}
        	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+FSNSET" , item ));
}

void atInst::init_sn()
{
	// 语法检查的正则表达式， 功能描述 ，错误提示信息
	stAtHash  item("AT\\+SN\\?{0,1}\\r" , "Get device serial number." , "AT+SN[?]<RET>" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		dtu * ptdtu = GetOrCreateDTU();
		if( ptdtu ){
			if( params.size() > 0 ){
				ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				str = AT_OK_STR + "+SN:" + ptdtu->SN() + "\r\n";
			}
		}else{
			ss<<"\r\n+ERR:" << ERR_SYS_ERROR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SN" , item ));
}

void atInst::init_iccid()
{
    	// 语法检查的正则表达式， 功能描述 ，错误提示信息
    	stAtHash  item("AT\\+ICCID\\?{0,1}\\r" , "Get SIM Card ICCID." , "AT+ICCID[?]<RET>" );

    	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;

		if( params.size() > 0 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			//char data[ 40 ];
			int slot = 0;
			E_QL_SIM_ID_T  simId = E_QL_SIM_EXTERNAL_SLOT_1;

			std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
            		try{
                		if( ptvar ) ptvar->GetValue( "/simType" , slot );
            		}catch( ... ){ 
				slot = 0;
			}
            		switch( slot ){
            		case 0:
                		simId = E_QL_SIM_EXTERNAL_SLOT_1;
                	break;
            		case 1:
                		simId = E_QL_SIM_EXTERNAL_SLOT_2;
                	break;
            		case 2:
                		simId = E_QL_SIM_EMBEDDED;
                	break;
            		case 3:
                		simId = E_QL_SIM_REMOTE;
                	break;
            		}
            		E_QL_SIM_STATES_T stat = QL_SIM_GetState( simId );
            //int e = -1;
            		switch( stat ){
            		case E_QL_SIM_STAT_NOT_INSERTED:
                		ss << "+ERR:" << ERR_MISSING_SIM_CARD << "\r\n";
                		str = std::move( ss.str() );
                	break;
            		case E_QL_SIM_STAT_READY:
            		{
                		char iccid[ 21 ];
                		QL_SIM_GetICCID( simId , iccid , 20 );
                		iccid[ 20 ] = 0;
		                ss << AT_OK_STR << "+ICCID:" << iccid << "\r\n";
				str = std::move( ss.str() );
            		}
                	break;
            		case E_QL_SIM_STAT_PIN_REQ:
            		case E_QL_SIM_STAT_PUK_REQ:
            		case E_QL_SIM_STAT_BUSY:
                		ss << "+ERR:" << ERR_SIM_BUSY << "\r\n";
                		str = std::move( ss.str() );
                	break;
            		case E_QL_SIM_STAT_BLOCKED:
                		ss << "+ERR:" << ERR_SIM_BLOCKED << "\r\n";
                		str = std::move( ss.str() );
                		break;
            		case E_QL_SIM_STAT_UNKNOWN:
            		default:
                		ss << "+ERR:" << ERR_UNKNOW_SIM_STATE << "\r\n";
                		str = std::move( ss.str() );
                	break;
            		}
        	}
        	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+ICCID" , item) );
}

void atInst::init_imei()
{
	// 语法检查的正则表达式， 功能描述 ，错误提示信息
	stAtHash  item("AT\\+IMEI\\?{0,1}\\r" , "Get device IMEI." , "AT+IMEI[?]<RET>" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::stringstream ss;
		std::string str;
		if( params.size() > 0 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			char data[ 40 ];
			int e = QL_DEV_GetImei( data , 15 );

			if( e == 0 ){
				data[ 15 ] = 0;
				ss << AT_OK_STR << "+IMEI:" << data << "\r\n";
				str = ss.str();
			}else{
				ss << "\r\n+ERR:" << ERR_SYS_ERROR << "\r\n";
				str = ss.str();
			}
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+IMEI" , item) );
}

void atInst::init_uart()
{
	stAtHash  item("AT\\+UART(\\?|=\\d+\\,[78]\\,[12]\\,(NONE|ODD|EVEN)\\,NFC){0,1}\\r" ,
			"Get or Set uart parameters." ,
			"AT+UART[?]<RET> get uart parameters\nAT+UART=[baud],[character bits],[stop bits],[parity],[NFC]<RET> Set uart parameters.see user manual for details." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		int baud , cl , s , p , f;
			
		if( params.size() > 0 && params.size() != 5 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
			response( at , str );
			return;
		}
        	std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
        	if( ptvar ){
			if( params.size() > 0 ){ // 设置操作

				ss << params[ 0 ];    ss >> baud;     ss.clear();  ss.str("");
				ss << params[ 1 ];    ss >> cl;       ss.clear();  ss.str("");
				switch( baud ){
				case 1200:    case 2400:   case 4800:   case 9600:   case 19200:    case 38400:
				case 57600:  case 115200: case 230400:   case 460800:
				case 921600: case 3000000:       break;
				default:
				ss << "\r\n+ERR:" << ERR_UNSUPPORTED_BAUD<< "\r\n";
				str = ss.str();
				response( at , str );
				return;
			}

			if( params[ 2 ] == "1") s = 1;
			else if( params[ 2 ] == "2" ) s = 3;
			else{
				ss.clear();    ss.str("");
				ss << "\r\n+ERR:" << ERR_UNSUPPORTED_STOP<< "\r\n";
				str = ss.str();
				response( at , str );
				return;
			}

			if( params[ 3 ] == "NONE" ) p = 0;
			else if( params[ 3 ] == "EVEN" ) p = 1;
			else if( params[ 3 ] == "ODD" ) p = 2;
			else{
				ss.clear();         ss.str("");
				ss << "\r\n+ERR:" << ERR_UNSUPPORTED_PARITY << "\r\n";
				str = ss.str();
				response( at , str );
				return;
			}
			if( params[ 4 ] == "NFC" ) f = 0;
			else if( params[ 4 ] == "HARD" ) f = 1;
			else if( params[ 4 ] == "SOFT" ) f = 2;
			else{
				ss.clear();        ss.str("");
				ss << "\r\n+ERR:" << ERR_UNSUPPORTED_FLOW << "\r\n";
				str = ss.str();
				response( at , str );
				return;
			}
			ss << params[ 4 ];    ss >> f;
			ptvar->SetValue( "/serial/com1/baud" ,     baud );
			ptvar->SetValue( "/serial/com1/char_len" , cl   );
			ptvar->SetValue( "/serial/com1/stop" ,     s    );
			ptvar->SetValue( "/serial/com1/parity" ,   p    );
			ptvar->SetValue( "/serial/com1/flow" ,     f    );
			str = AT_OK_STR;
            	}else{  // 查询操作
			ptvar->GetValue( "/serial/com1/baud" , baud );
			ptvar->GetValue( "/serial/com1/char_len" , cl );
			ptvar->GetValue( "/serial/com1/stop" , s );
			ptvar->GetValue( "/serial/com1/parity" , p );
			ptvar->GetValue( "/serial/com1/flow" , f );
			ss.clear(); ss.str("");
			ss << AT_OK_STR << "+UART:" << baud << "," << cl << "," << ( s == 1 ? 1 : 2 )
			<< "," << ( p == 0 ? "NONE": ( p == 1 ? "EVEN" : "ODD" ) )
			<< "," << ( f == 0 ? "NFC" : ( f == 1 ? "HARD" :  "SOFT" ) ) << "\r\n";
			str = ss.str();
            	}
	}else{ // 系统变量入口错误
		ss.clear(); ss.str();
		ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
		str = ss.str();
		}
	response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+UART" , item) );
}

void atInst::init_uartft()
{// 查询设置串口打包间隔时间
	stAtHash  item("AT\\+UARTFT(\\?|=[1-9]\\d{2,5}){0,1}\\r" ,
			"Get or set uart package intval time, unit ms, must between 50~60000ms" ,
			"AT+UARTFT[?]<RET> get uart package intval time\n AT+UARTFT=[digit]<RET> set uart package intval time." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				int data;
				ss << params[ 0 ];    
				ss >> data;
				ss.clear();
				ss.str("");
				__show_line_1( "%s%s data = %d%s", TYELLOW , __PRETTY_FUNCTION__ , data , TNORMAL );
				if( ( data < 50 ) || (data > 60000) ){
					std::stringstream ss1;
					__show_line_2();
					ss1 << "+ERR:" << ERR_BAD_PACK_INTVAL << "\r\n";
					str = ss1.str();
				}else{
					ptvar->SetValue( "/serial/com1/pkg_intval" , data );
					str = AT_OK_STR;
				}
		}else if( params.size() > 1 ){
			ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			int data;
			ptvar->GetValue("/serial/com1/pkg_intval" , data );

			ss << AT_OK_STR << "+UARTFT:" << data << "\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+UARTFT" , item) );
}

void atInst::init_uartfl()
{ // 设置打包长度
	stAtHash  item("AT\\+UARTFL(\\?|=[1-9]\\d{1,4}){0,1}\\r" ,
			"Get or set uart package length." ,
			"AT+UARTFL[?]<RET> get uart package length\nAT+UARTFL=(digits)<RET> set uart package length." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			int data;
			ss << params[ 0 ];
			ss >> data;
			if( data < 1 || data > 1024 ){
				ss << "\r\n+ERR:" << ERR_BAD_PACK_LENGTH << "\r\n";
				str = ss.str();
			}else{
				ptvar->SetValue( "/serial/com1/pkg_length" , data );
				str = AT_OK_STR;
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			int data;
			ptvar->GetValue("/serial/com1/pkg_length" , data );

			ss << AT_OK_STR << "+UARTFL:" << data << "\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+UARTFL" , item ));
}

void atInst::init_rfcen()
{// 语法检查的正则表达式， 功能描述 ，错误提示信息
    	stAtHash  item("AT\\+RFCEN(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set RFC2217 switch status" ,
                   "AT+RFCEN[?]<RET> get status.\nAT+RFCEN=(ON|OFF)<RET> set status" );

    	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ] == "ON" ){
				ptvar->SetValue( "/serial/com1/rfcen" , true );
			}
			else{
				ptvar->SetValue( "/serial/com1/rfcen" , false );
			}
			str = AT_OK_STR;
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			bool d = false;
			ptvar->GetValue( "/serial/com1/rfcen" , d);
			str = AT_OK_STR + "+RFCEN:" + ( d == true ? "ON":"OFF" )  + "\r\n";
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+RFCEN" , item) );
}

void atInst::init_uartpk()
{
	stAtHash  item("AT\\+UARTPK(\\?|=(STREAM|TIME|LENGTH|MIX)){0,1}\\r" ,
			"Get or set APN UART Packet method." ,
			"AT+UARTPK[?]<RET> get method \nAT+UARTPK=(method)<RET> set method parameter" );

	item.fun = [this](const std::string& at , const ArrayString& params ){

		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){ // 设置
				int value = 0;
				switch( hash_(params[ 0 ].c_str() ) ){
				case hash_compile_time("STREAM"):   default: value = 3; break;
				case hash_compile_time("TIME"):              value = 1; break;
				case hash_compile_time("LENGTH"):            value = 0; break;
				case hash_compile_time("MIX"):               value = 2; break;
				}
				ptvar->SetValue( "/serial/com1/packet" , value );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){ // 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{   // 查询
				int value = 3;
				ptvar->GetValue( "/serial/com1/packet" , value );
				switch( value ){
				case 0: ss << AT_OK_STR << "+UARTPK:LENGTH\r\n"; break;
				case 1: ss << AT_OK_STR << "+UARTPK:TIME\r\n"; break;
				case 2: ss << AT_OK_STR << "+UARTPK:MIX\r\n"; break;
				case 3: ss << AT_OK_STR << "+UARTPK:STREAM\r\n"; break;
				default: ss << "\r\n+ERR:" << ERR_ENUM_FAULT << "\r\n"; break;
				}

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+UARTPK" , item ));
}
void atInst::init_apn()
{ // 设置APN
	stAtHash  item("AT\\+APN(\\?|=\\w+\\,\\w+\\,\\w+){0,1}\\r" ,
			"Get or set APN parameters" ,
			"AT+APN[?]<RET> get APN parameters\nAT+APN=(net),(user),(password)<RET> set APN parameters" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 3 ){
				ptvar->SetValue( "/net/apn/net" , params[ 0 ] );
				ptvar->SetValue( "/net/apn/user" , params[ 1 ] );
				ptvar->SetValue( "/net/apn/passwd" , params[ 2 ] );
				int rst = apn_set( params[ 0 ] , params[ 1 ] , params[ 2 ] );
				if( rst == 0 )
					str = AT_OK_STR;
				else{
					ss << "\r\n+ERR:" << ERR_SET_APN << "\r\n";
					str = ss.str();
				}
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				std::string tmp;
				ptvar->GetValue( "/net/apn/net" , tmp );
				ss << AT_OK_STR << "+APN:\"" << tmp;
				ptvar->GetValue( "/net/apn/user" , tmp );
				ss << "\",\"" << tmp;
				ptvar->GetValue( "/net/apn/passwd" , tmp );
				ss << "\",\"" << tmp << "\"\r\n";

				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );

	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+APN" , item ));
}

void atInst::init_socka()
{ //
    	stAtHash  item("AT\\+SOCKA(\\?|=((TCP|UDP)\\,(\\w|\\W)+\\,\\d{1,5})){0,1}\\r" ,
                   "Get or set socket parameters" ,
                   "AT+SOCKA[?]<RET> get socket parameters\nAT+SOCKA=(protocol),(server),(port)<RET> set parameters" );

    	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){// 设置数据
			if( params.size() == 3 ){
				ptvar->SetValue( "/net/socket/sock1/protocol" , params[ 0 ] );   // 链接协议
				ptvar->SetValue( "/net/socket/sock1/server" , params[ 1 ]);
				int port;
				ss << params[ 2 ];                ss >> port;
				ptvar->SetValue( "/net/socket/sock1/port" , port );

				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{// 查询数据
				ptvar->GetValue( "/net/socket/sock1/protocol" , str );
				ss << AT_OK_STR << "+SOCKA:" << str;
				ptvar->GetValue( "/net/socket/sock1/server" , str );
				ss << "," << str ;
				int port;
				ptvar->GetValue( "/net/socket/sock1/port" , port );
				ss << "," << port << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKA" , item ) );
}

void atInst::init_sockb()
{
	stAtHash  item("AT\\+SOCKB(\\?|=((TCP|UDP)\\,(\\w|\\W)+\\,\\d{1,5})){0,1}\\r" ,
			"Get or set socket parameters" ,
			"AT+SOCKB[?]<RET> get socket parameters\nAT+SOCKB=(protocol),(server),(port)<RET> set parameters" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 3 ){
				ptvar->SetValue( "/net/socket/sock2/protocol" , params[ 0 ] );   // 链接协议
				ptvar->SetValue( "/net/socket/sock2/server" , params[ 1 ]);
				int port ;
				ss << params[ 2 ];
				ss >> port;
				ptvar->SetValue( "/net/socket/sock2/port" , port );

				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock2/protocol" , str );
				ss << AT_OK_STR << "+SOCKB:" << str;
				ptvar->GetValue( "/net/socket/sock2/server" , str );
				ss << "," << str ;
				int port;
				ptvar->GetValue( "/net/socket/sock2/port" , port );
				ss << "," << port << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKB" , item ));
}

void atInst::init_sockc()
{
	stAtHash  item("AT\\+SOCKC(\\?|=((TCP|UDP)\\,(\\w|\\W)+\\,\\d{1,5})){0,1}\\r" ,
			"Get or set socket parameters" ,
			"AT+SOCKC[?]<RET> get socket parameters\nAT+SOCKC=(protocol),(server),(port)<RET> set parameters" );

	item.fun = [this](const std::string& at , const ArrayString& params ){

		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 3 ){
				ptvar->SetValue( "/net/socket/sock3/protocol" , params[ 0 ] );   // 链接协议
				ptvar->SetValue( "/net/socket/sock3/server" , params[ 1 ]);
				int port ;
				ss << params[ 2 ];
				ss >> port;
				ptvar->SetValue( "/net/socket/sock3/port" , port );

				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock3/protocol" , str );
				ss << AT_OK_STR << "+SOCKC:" << str;
				ptvar->GetValue( "/net/socket/sock3/server" , str );
				ss << "," << str ;
				int port;
				ptvar->GetValue( "/net/socket/sock3/port" , port );
				ss << "," << port << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKC" , item ));
}

void atInst::init_sockd()
{
	stAtHash  item("AT\\+SOCKD(\\?|=((TCP|UDP)\\,(\\w|\\W)+\\,\\d{1,5})){0,1}\\r" ,
			"Get or set socket parameters" ,
			"AT+SOCKD[?]<RET> get socket parameters\nAT+SOCKD=(protocol),(server),(port)<RET> set parameters" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 3 ){
				ptvar->SetValue( "/net/socket/sock4/protocol" , params[ 0 ] );   // 链接协议
				ptvar->SetValue( "/net/socket/sock4/server" , params[ 1 ]);
				int port ;
				ss << params[ 2 ];
				ss >> port;
				ptvar->SetValue( "/net/socket/sock4/port" , port );

				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock4/protocol" , str );
				ss << AT_OK_STR << "+SOCKD:" << str;
				ptvar->GetValue( "/net/socket/sock4/server" , str );
				ss << "," << str ;
				int port;
				ptvar->GetValue( "/net/socket/sock4/port" , port );
				ss << "," << port << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

			response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKD" , item ));
}

void atInst::init_sockaen()
{
	stAtHash  item("AT\\+SOCKAEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Get or set socket switch." ,
			"AT+SOCKAEN[?]<RET> get socket switch status\nAT+SOCKAEN=(ON|OFF) set socket switch status" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
			
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			__show_line_1( "%sPARAM COUNT = %d%s" , TRED , (int)params.size() , TNORMAL );
			if( params.size() == 1 ){
				__show_line_1( "%s%s%s" , TYELLOW , params[ 0 ].c_str() , TNORMAL );
				bool v = false;
				v  = ( params[ 0 ].find("ON") != std::string::npos );
				ptvar->SetValue("/net/socket/sock1/enable" , v );

				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				bool d;
				ptvar->GetValue( "/net/socket/sock1/enable" , d );

				ss << AT_OK_STR << "+SOCKAEN:" << (d == true ? "ON" : "OFF") << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKAEN" , item ));
}

void atInst::init_sockben()
{
	stAtHash  item("AT\\+SOCKBEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Get or set socket switch." ,
			"AT+SOCKBEN[?]<RET> get socket switch status\nAT+SOCKBEN=(ON|OFF) set socket switch status" );

	item.fun = [this](const std::string& at , const ArrayString& params ){

		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue("/net/socket/sock2/enable" , params[ 0 ].find("ON") != std::string::npos ? true : false );
			
				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				bool d;
				ptvar->GetValue( "/net/socket/sock2/enable" , d );

				ss << AT_OK_STR << "+SOCKBEN:" << (d == true ? "ON" : "OFF") << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKBEN" , item ));
}

void atInst::init_sockcen()
{
	stAtHash  item("AT\\+SOCKCEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Get or set socket switch." ,
			"AT+SOCKCEN[?]<RET> get socket switch status\nAT+SOCKCEN=(ON|OFF) set socket switch status" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue("/net/socket/sock3/enable" , params[ 0 ].find("ON") != std::string::npos ? true : false );
				
				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				bool d;
				ptvar->GetValue( "/net/socket/sock3/enable" , d );

				ss << AT_OK_STR << "+SOCKCEN:" << (d == true ? "ON" : "OFF") << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKCEN" , item ));
}

void atInst::init_sockden()
{
    stAtHash  item("AT\\+SOCKDEN(\\?{0,1}|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket switch." ,
                   "AT+SOCKDEN[?]<RET> get socket switch status\nAT+SOCKDEN=(ON|OFF) set socket switch status" );

    item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue("/net/socket/sock4/enable" , params[ 0 ].find("ON") != std::string::npos ? true : false );

				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				bool d;
				ptvar->GetValue( "/net/socket/sock4/enable" , d );

				ss << AT_OK_STR << "+SOCKDEN:" << (d == true ? "ON" : "OFF") << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKDEN" , item ));
}

void atInst::init_sockasl()
{
	stAtHash  item("AT\\+SOCKASL(\\?|=(SHORT|LONG)){0,1}\\r" ,
			"Get or set socket connection type." ,
			"AT+SOCKASL[?]<RET> Get socket connection type.\nAT+SOCKASL=(SHORT|LONG)<RET> Set socket connection type." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "LONG" || params[ 0 ] == "SHORT" ){
					ptvar->SetValue("/net/socket/sock1/link" , params[ 0 ] );

					str = AT_OK_STR;
				}else if( params.size() > 0 ){
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = ss.str();
				}else{
					ss << "\r\n+ERR:" << ERR_LINK_TYPE << "\r\n";
					str = ss.str();
				}
			}else{

				ptvar->GetValue( "/net/socket/sock1/link" , str );

				ss << AT_OK_STR << "+SOCKASL:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKASL" , item ));
}

void atInst::init_sockbsl()
{
	stAtHash  item("AT\\+SOCKBSL(\\?|=(SHORT|LONG)){0,1}\\r" ,
			"Get or set socket connection type." ,
			"AT+SOCKBSL[?]<RET> Get socket connection type.\nAT+SOCKBSL=(SHORT|LONG)<RET> Set socket connection type." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "LONG" || params[ 0 ] == "SHORT" ){
				ptvar->SetValue("/net/socket/sock2/link" , params[ 0 ] );

				str = AT_OK_STR;
				}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
				}else{
				ss << "\r\n+ERR:" << ERR_LINK_TYPE << "\r\n";
				str = ss.str();
				}
			}else{

				ptvar->GetValue( "/net/socket/sock2/link" , str );

				ss << AT_OK_STR << "+SOCKBSL:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKBSL" , item) );
}

void atInst::init_sockcsl()
{
	stAtHash  item("AT\\+SOCKCSL(\\?|=(SHORT|LONG)){0,1}\\r" ,
			"Get or set socket connection type." ,
			"AT+SOCKCSL[?]<RET> Get socket connection type.\nAT+SOCKCSL=(SHORT|LONG)<RET> Set socket connection type." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "LONG" || params[ 0 ] == "SHORT" ){
					ptvar->SetValue("/net/socket/sock3/link" , params[ 0 ] );

					str = AT_OK_STR;
				}else if( params.size() > 0 ){
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = ss.str();
				}else{
					ss << "\r\n+ERR:" << ERR_LINK_TYPE << "\r\n";
					str = ss.str();
				}
			}else{

				ptvar->GetValue( "/net/socket/sock3/link" , str );

				ss << AT_OK_STR << "+SOCKCSL:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKCSL" , item) );
}

void atInst::init_sockdsl()
{
	stAtHash  item("AT\\+SOCKDSL(\\?|=(SHORT|LONG)){0,1}\\r" ,
			"Get or set socket connection type." ,
			"AT+SOCKDSL[?]<RET> Get socket connection type.\nAT+SOCKDSL=(SHORT|LONG)<RET> Set socket connection type." );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string       str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "LONG" || params[ 0 ] == "SHORT" ){
					ptvar->SetValue("/net/socket/sock4/link" , params[ 0 ] );

					str = AT_OK_STR;
				}else if( params.size() > 0 ){
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = ss.str();
				}else{
					ss << "\r\n+ERR:" << ERR_LINK_TYPE << "\r\n";
					str = ss.str();
				}
			}else{
				ptvar->GetValue( "/net/socket/sock4/link" , str );

				ss << AT_OK_STR << "+SOCKDSL:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKDSL" , item ) );
}
void atInst::init_sockalk()
{
	stAtHash  item("AT\\+SOCKALK\\?{0,1}\\r" ,
			"Check connection status." ,
			"AT+SOCKALK[?]<RET>" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string       str;
		std::stringstream ss;

		dtu * ptdtu = GetOrCreateDTU();
		if( params.size() > 0 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			if( ptdtu ){
				bool rst = ptdtu->Link( 1 );
				str = AT_OK_STR + "+SOCKALK:" + ( rst == true ? "ON" : "OFF" ) + "\r\n";
			}else{
				ss << "\r\n+ERR:" << ERR_SYS_ERROR << "\r\n";
				str = ss.str();
			}
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKALK" , item ));
}
void atInst::init_sockblk()
{
	stAtHash  item("AT\\+SOCKBLK\\?{0,1}\\r" ,
			"Check connection status." ,
			"AT+SOCKBLK[?]<RET>" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string       str;
		std::stringstream ss;
		if( params.size() > 0 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			dtu * ptdtu = GetOrCreateDTU();
			if( ptdtu ){
				bool rst = ptdtu->Link( 2 );
				str = AT_OK_STR + "+SOCKBLK:" + ( rst == true ? "ON" : "OFF" ) + "\r\n";
			}else{
				ss << "\r\n+ERR:" << ERR_SYS_ERROR << "\r\n";
				str = ss.str();
			}
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKBLK" , item ));
}

void atInst::init_sockclk()
{
	stAtHash  item("AT\\+SOCKCLK\\?{0,1}\\r" ,
			"Check connection status." ,
			"AT+SOCKCLK[?]<RET>" );

	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str;
		dtu * ptdtu = GetOrCreateDTU();
		if( ptdtu ){
			bool rst = ptdtu->Link( 3 );
			str = AT_OK_STR + "+SOCKCLK:" + ( rst == true ? "ON" : "OFF" )+ "\r\n";
		}else{
			str = AT_OK_STR + "+SOCKCLK:OFF" + "\r\n";
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKCLK" , item ) );
}

void atInst::init_sockdlk()
{
	stAtHash  item("AT\\+SOCKDLK\\?{0,1}\\r" ,
			"Check connection status." ,
			"AT+SOCKDLK[?]<RET>" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		dtu * ptdtu = GetOrCreateDTU();
		if( ptdtu ){
			bool rst = ptdtu->Link( 4 );
			str = AT_OK_STR + "+SOCKDLK:" + ( rst == true ? "ON" : "OFF" )+ "\r\n";
		}else{
			str = AT_OK_STR + "+SOCKDLK:OFF" + "\r\n";
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKDLK" , item ) );
}

void atInst::init_shorato()
{
	stAtHash  item("AT\\+SHORATO(\\?|=[1-9]\\d{1,3}){0,1}\\r" ,
			"Get or set socket short connection intval time, between 1~100s" ,
			"AT+SHORATO[?]<RET> Get intval time\nAT+SHORATO=(digits)<RET> set intval time." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){// 设置
				ss << params[ 0 ];
				ss >> rt;
				if( rt > 100 ) rt = 100;
				if( rt < 1 ) rt = 1;

				ptvar -> SetValue( "/net/socket/sock1/shortReconn" , rt );

				str= AT_OK_STR; //
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{ // 查询
				ptvar->GetValue( "/net/socket/sock1/shortReconn" , rt );
				ss << AT_OK_STR + "+SHORATO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SHORATO" , item ) );
}

void atInst::init_shorbto()
{
	stAtHash  item("AT\\+SHORBTO(\\?|=[1-9]\\d{0,2}){0,1}\\r" ,
			"Get or set socket short connection intval time, between 1~100s" ,
			"AT+SHORBTO[?]<RET> Get intval time\nAT+SHORBTO=(digits)<RET> set intval time." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){// 设置
				ss << params[ 0 ];
				ss >> rt;
				if( rt > 100 ) rt = 100;
				if( rt < 1 ) rt = 1;

				ptvar -> SetValue( "/net/socket/sock2/shortReconn" , rt );

				str= AT_OK_STR; //
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{ // 查询

				ptvar->GetValue( "/net/socket/sock2/shortReconn" , rt );
				ss << AT_OK_STR + "+SHORATO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SHORBTO" , item ) );
}

void atInst::init_shorcto()
{
	stAtHash  item("AT\\+SHORCTO(\\?|=[1-9]\\d{0,2}){0,1}\\r" ,
			"Get or set socket short connection intval time, between 1~100s" ,
			"AT+SHORCTO[?]<RET> Get intval time\nAT+SHORCTO=(digits)<RET> set intval time." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){// 设置
				ss << params[ 0 ];
				ss >> rt;
				if( rt > 100 ) rt = 100;
				if( rt < 1 ) rt = 1;

				ptvar -> SetValue( "/net/socket/sock3/shortReconn" , rt );

				str= AT_OK_STR; //
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{ // 查询
				ptvar->GetValue( "/net/socket/sock3/shortReconn" , rt );
				ss << AT_OK_STR + "+SHORCTO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
		ss.clear(); ss.str();
		ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
		str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SHORCTO" , item ) );
}

void atInst::init_shordto()
{
	stAtHash  item("AT\\+SHORDTO(\\?|=[1-9]\\d{0,2}){0,1}\\r" ,
			"Get or set socket short connection intval time, between 1~100s" ,
			"AT+SHORDTO[?]<RET> Get intval time\nAT+SHORDTO=(digits)<RET> set intval time." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){// 设置
				ss << params[ 0 ];
				ss >> rt;
				if( rt > 100 ) rt = 100;
				if( rt < 1 ) rt = 1;

				ptvar -> SetValue( "/net/socket/sock4/shortReconn" , rt );

				str= AT_OK_STR; //
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{ // 查询

				ptvar->GetValue( "/net/socket/sock4/shortReconn" , rt );
				ss << AT_OK_STR + "+SHORDTO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SHORDTO" , item ) );
}

void atInst::init_sockato()
{
	stAtHash  item("AT\\+SOCKATO(\\?|=\\d{1,3}){0,1}\\r" ,
			"Get or set socket reconnect intval , between 1~100s." ,
			"AT+SOCKATO[?]<RET> Get reconnect intval\nAT+SOCKATO=(DIGIT)<RET> set reconnect intval" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){ // 设置
				ss << params[ 0 ];
				ss >> rt;
				if( rt > 100 || rt < 1 ){
					ss << "\r\n+ERR:" << ERR_CONN_TIME_OFR << "\r\n";
					str = ss.str();
				}else{
					ptvar->SetValue( "/net/socket/sock1/reconnectTime" , rt );
					str = AT_OK_STR;
				}
				
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{  // 查询
				ptvar->GetValue("/net/socket/sock1/reconnectTime" , rt );
				ss << AT_OK_STR << "+SOCKATO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKATO" , item ) );
}

void atInst::init_sockbto()
{
	stAtHash  item("AT\\+SOCKBTO(\\?|=\\d{1,3}){0,1}\\r" ,
			"Get or set socket reconnect intval , between 1~100s." ,
			"AT+SOCKBTO[?]<RET> Get reconnect intval\nAT+SOCKBTO=(DIGIT)<RET> set reconnect intval" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;

		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){ // 设置
				ss << params[ 0 ];
				ss >> rt;

				ptvar->SetValue( "/net/socket/sock2/reconnectTime" , rt );
				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{  // 查询
				ptvar->GetValue("/net/socket/sock2/reconnectTime" , rt );
				ss << AT_OK_STR << "+SOCKBTO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKBTO" , item ) );
}

void atInst::init_sockcto()
{
	stAtHash  item("AT\\+SOCKCTO(\\?|=\\d{1,3}){0,1}\\r" ,
			"Get or set socket reconnect intval , between 1~100s." ,
			"AT+SOCKCTO[?]<RET> Get reconnect intval\nAT+SOCKCTO=(DIGIT)<RET> set reconnect intval" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;

		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){  // 设置
				ss << params[ 0 ];
				ss >> rt;

				ptvar->SetValue( "/net/socket/sock3/reconnectTime" , rt );
				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{  // 查询
				ptvar->GetValue("/net/socket/sock3/reconnectTime" , rt );
				ss << AT_OK_STR << "+SOCKCTO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKCTO" , item ) );
}
void atInst::init_sockdto()
{
	stAtHash  item("AT\\+SOCKDTO(\\?|=\\d{1,3}){0,1}\\r" ,
			"Get or set socket reconnect intval , between 1~100s." ,
			"AT+SOCKDTO[?]<RET> Get reconnect intval\nAT+SOCKDTO=(DIGIT)<RET> set reconnect intval" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		int                        rt;

		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){ // 设置
				ss << params[ 0 ];
				ss >> rt;

				ptvar->SetValue( "/net/socket/sock4/reconnectTime" , rt );
				str = AT_OK_STR;
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{  // 查询
				ptvar->GetValue("/net/socket/sock4/reconnectTime" , rt );
				ss << AT_OK_STR << "+SOCKDTO:" << rt << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKDTO" , item ) );
}

void atInst::init_sockind()
{
	return;  // 这是故意这么做的，后继可能会删除这个函数
	stAtHash  item("AT\\+SOCKIND(\\?|=(ON|OFF)){0,1}\r" ,
			"Get or set socket index switch status." ,
			"AT+SOCKIND[?]<RET> Get status\nAT+SOCKIND=(ON|OFF)<RET> set switch status." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;

		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() > 0 ){
				ptvar->SetValue( "/net/sockIndexEn" , ( params[ 0 ]=="ON" ? true : false) );
				str = AT_OK_STR;
			}else{
				bool flag = false;
				ptvar->SetValue( "/net/sockIndexEn" , flag );
				if( flag ){
				ss << AT_OK_STR << "+SOCKIND:ON\r\n";
				}else{
				ss << AT_OK_STR << "SOCKIND:OFF\r\n";
				}

				str = ss.str();
			}
		}else{
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKIND" , item ) );
}

void atInst::init_sdpen()
{
	stAtHash  item("AT\\+SDPEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Get or set dispatch protocol switch status." ,
			"AT+SDPEN[?]<RET> Get switch status.\nAT+SDPEN=(ON|OFF) Set switch status." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){

		std::string               str;
		std::shared_ptr< CSysVar> ptvar = GetOrCreateSysVar ();
		std::stringstream         ss;
		bool                      en    = false;
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "ON" ){
				ptvar->SetValue( "/net/sdpen" , true );
				str = AT_OK_STR;
				}else if( params[ 0 ] == "OFF" ){
				ptvar->SetValue( "/net/sdpen" , false );
				str = AT_OK_STR;
				}else{
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
				str = ss.str();
				}
			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/sdpen" , en );
				if( en )
				ss << AT_OK_STR << "+SDPEN:ON\r\n";
				else
				ss << AT_OK_STR << "+SDPEN:OFF\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SDPEN" , item ) );
}

void atInst::init_regen()
{
	stAtHash  item("AT\\+REGEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Get or set register package switch status." ,
			"AT+REGEN[?]<RET> Get status;\nAT+REGEN=(ON|OFF) set status." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		bool                     en = false;
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "ON" ){
					ptvar->SetValue( "/net/socket/sock1/reg/enable" , true );
					ptvar->SetValue( "/net/socket/sock2/reg/enable" , true );
					ptvar->SetValue( "/net/socket/sock3/reg/enable" , true );
					ptvar->SetValue( "/net/socket/sock4/reg/enable" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ] == "OFF" ){
					ptvar->SetValue( "/net/regen" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = ss.str();
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{// 查询
				ptvar->GetValue( "/net/socket/sock1/reg/enable" , en );
				if( en )
				ss << AT_OK_STR << "+REGEN:ON\r\n";
				else
				ss << AT_OK_STR << "+REGEN:OFF\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGEN" , item ) );
}
void atInst::init_regtp()
{
	stAtHash  item("AT\\+REGTP(\\?|=(ICCID|IMEI|CLOUD|USER)){0,1}\\r" ,
			"Get or set register package content type." ,
			"AT+REGTP[?]<RET> Get type.\nAT+REGTP=(type)<REG> set type." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		std::string str , tmp_str;
		std::stringstream  ss;
		if( ptvar ){
			bool flag = false;
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() )){
				case hash_compile_time( "ICCID" ): case hash_compile_time ( "IMEI" ):
				case hash_compile_time( "CLOUD" ): case hash_compile_time ( "USE" ):
				flag = true;                    break;
				default:flag = false; break;
				}

				if( flag ){
					ptvar->SetValue( "/net/socket/sock1/reg/data_type" , params[ 0 ] );
					ptvar->SetValue( "/net/socket/sock2/reg/data_type" , params[ 0 ] );
					ptvar->SetValue( "/net/socket/sock3/reg/data_type" , params[ 0 ] );
					ptvar->SetValue( "/net/socket/sock4/reg/data_type" , params[ 0 ] );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
					str = ss.str();
				}


			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ss << AT_OK_STR << "+REGTP:";
				ptvar->GetValue( "/net/socket/sock1/reg/data_type" , tmp_str );
						ss  << tmp_str <<",";
				ptvar->GetValue( "/net/socket/sock2/reg/data_type" , tmp_str );
						ss  << tmp_str <<",";
				ptvar->GetValue( "/net/socket/sock3/reg/data_type" , tmp_str );
						ss  << tmp_str <<",";
				ptvar->GetValue( "/net/socket/sock4/reg/data_type" , tmp_str );
				ss  << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGTP" , item ) );
}

void atInst::init_regsnd()
{
	stAtHash  item("AT\\+REGSND(\\?|=(LINK|DATA)){0,1}\\r" ,
			"Get or set register package send type." ,
			"AT+REGSND[?]<RET> Get send type.\nAT+REGSEND=(LINK|DATA)<RET> Set send type" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 		    str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;

		if( ptvar ){
		if( params.size() == 1 ){
			bool flag = false;
			flag = false;
			switch( hash_( params[ 0 ].c_str() ) ){
			case hash_compile_time( "LINK" ): flag = true; break;
			case hash_compile_time( "DATA" ): flag = true; break;
			default: flag = false;  break;
			}

			if( flag == true ){
				ptvar->SetValue( "/net/socket/sock1/reg/type" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock2/reg/type" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock3/reg/type" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock4/reg/type" , params[ 0 ] );
				str = AT_OK_STR;
			}else{// 可选项错误
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
				str = ss.str();
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			ss << AT_OK_STR << "+REGSND:";
			ptvar->GetValue( "/net/socket/sock1/reg/type" , str );
			ss << str << ",";
			ptvar->GetValue( "/net/socket/sock2/reg/type" , str );
			ss << str << ",";
			ptvar->GetValue( "/net/socket/sock3/reg/type" , str );
			ss << str << ",";
			ptvar->GetValue( "/net/socket/sock4/reg/type" , str );
			ss << str << "\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGSND" , item ) );
}

void atInst::init_regdt()
{
	stAtHash  item("AT\\+REGDT(\\?|=(\\w|\\.|-|_|\\*|#|\\$)+){0,1}\\r" ,
			"Get or set register package data." ,
			"AT+REGDT[?]<RET> Get data.\nAT+REGDT=(data)<RET> Set data." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 				str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock1/reg/data" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock2/reg/data" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock3/reg/data" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock4/reg/data" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ss << AT_OK_STR << "+REGDT:";
				ptvar->GetValue( "/net/socket/sock1/reg/data" , str );
				ss << str << ",";
				ptvar->GetValue( "/net/socket/sock2/reg/data" , str );
				ss << str << ",";
				ptvar->GetValue( "/net/socket/sock3/reg/data" , str );
				ss << str << ",";
				ptvar->GetValue( "/net/socket/sock4/reg/data" , str );
				ss << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
			response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGDT" , item ) );
}

void atInst::init_cloud()
{
	stAtHash  item("AT\\+CLOUD(\\?|=(\\w{20})\\,\\w{8}){0,1}\\r" ,
			"" ,
			"" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		std::stringstream ss;
		/**
		 * signalcloud 配合设置
		 */
		if( ptvar ){
			if( params.size() == 1 ){
				//ptvar->SetValue( "/regdata" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				//ptvar->GetValue( "/regdata" , str );
				ss << AT_OK_STR << "+CLOUD:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CLOUD" , item ) );
}

void atInst::init_hearten()
{
	stAtHash  item("AT\\+HEARTEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Get or set heart package switch status." ,
			"AT+HEARTEN[?]<RET> Get status.\n AT+HEARTEN=(ON|OFF)<RET> Set status" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		bool                       en = false;
		if( ptvar ){
		if( params.size() == 1 ){
			switch( hash_( params[ 0 ].c_str() ) ){
			case hash_compile_time( "ON" ):
				ptvar->SetValue( "/net/socket/sock1/heart/enable" , true );
				ptvar->SetValue( "/net/socket/sock2/heart/enable" , true );
				ptvar->SetValue( "/net/socket/sock3/heart/enable" , true );
				ptvar->SetValue( "/net/socket/sock4/heart/enable" , true );
				str = AT_OK_STR;
			break;
			case hash_compile_time( "OFF" ):
				ptvar->SetValue( "/net/socket/sock1/heart/enable" , false );
				ptvar->SetValue( "/net/socket/sock2/heart/enable" , false );
				ptvar->SetValue( "/net/socket/sock3/heart/enable" , false );
				ptvar->SetValue( "/net/socket/sock4/heart/enable" , false );
				str = AT_OK_STR;
			break;
			default:
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			break;
			}

		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			ss << AT_OK_STR << "+HEARTEN:";
			ptvar->GetValue("/net/socket/sock1/heart/enable" , en );
			if( en ){  ss << "ON,";  }else{  ss << "OFF,";  }
			ptvar->GetValue("/net/socket/sock2/heart/enable" , en );
			if( en ){  ss << "ON,";  }else{  ss << "OFF,";  }
			ptvar->GetValue("/net/socket/sock3/heart/enable" , en );
			if( en ){  ss << "ON,";  }else{  ss << "OFF,";  }
			ptvar->GetValue("/net/socket/sock4/heart/enable" , en );
			if( en ){  ss << "ON,";  }else{  ss << "OFF,";  }

			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTEN" , item ) );
}

void atInst::init_heartdt()
{
    stAtHash  item("AT\\+HEARTDT(\\?|=(\\w|\\.|-|_|\\*|#|\\$|@|\\&)+){0,1}\\r" ,
                   "Get or set heart package data." ,
                   "AT+HEARTDT[?]<RET> get data.\nAT+HEARTDT=(data)<RET> Set data." );

    item.fun = [this](const std::string& at ,const ArrayString& params ){
        std::string                str , tmp_str;
        std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
        std::stringstream          ss;

        if( ptvar ){
            if( params.size() == 1 ){
                ptvar->SetValue( "/net/socket/sock1/heart/data" , params[ 0 ] );
                ptvar->SetValue( "/net/socket/sock2/heart/data" , params[ 0 ] );
                ptvar->SetValue( "/net/socket/sock3/heart/data" , params[ 0 ] );
                ptvar->SetValue( "/net/socket/sock4/heart/data" , params[ 0 ] );

                str = AT_OK_STR;
            }else if( params.size() > 1 ){
                ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
                str = ss.str();
            }else{
				ss << AT_OK_STR << "+HEARTDT:";
                ptvar->GetValue( "/net/socket/sock1/heart/data" , str );
				ss << str << ",";
                ptvar->GetValue( "/net/socket/sock2/heart/data" , str );
				ss << str << ",";
                ptvar->GetValue( "/net/socket/sock3/heart/data" , str );
				ss << str << ",";
                ptvar->GetValue( "/net/socket/sock4/heart/data" , str );
                ss << str << "\r\n";
                str = ss.str();
            }
        }else{
            ss.clear(); ss.str();
            ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
            str = ss.str();
        }
		response( at , str );
    };

    m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTDT" , item ) );
}

void atInst::init_heartsnd()
{
	stAtHash  item("AT\\+HEARTSND(\\?|=(COM|NET)){0,1}\\r" ,
			"Get or set heart send direction." ,
			"AT+HEARTSND[?]<RET> Get heart send direction.\n AT+HEARTSND=(COM|NET)<RET> Set heart send direction." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                 str , tmp_str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream 			ss;

		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock1/heart/heart_send_dir" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock2/heart/heart_send_dir" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock3/heart/heart_send_dir" , params[ 0 ] );
				ptvar->SetValue( "/net/socket/sock4/heart/heart_send_dir" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ss << AT_OK_STR << "+HEARTSND:";
				ptvar->GetValue( "/net/socket/sock1/heart/heart_send_dir" , tmp_str );
				ss << tmp_str << ",";
				ptvar->GetValue( "/net/socket/sock2/heart/heart_send_dir" , tmp_str );
				ss << tmp_str << ",";
				ptvar->GetValue( "/net/socket/sock3/heart/heart_send_dir" , tmp_str );
				ss << tmp_str << ",";
				ptvar->GetValue( "/net/socket/sock4/heart/heart_send_dir" , tmp_str );
				ss << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTSND" , item ));
}

void atInst::init_hearttm()
{
	stAtHash  item("AT\\+HEARTTM(\\?|=[1-6]\\d{0,3}){0,1}\\r" ,
			"Get or set heart package send intval, between 1~60000s" ,
			"AT+HEARTTM[?]<RET> Get intval.\nAT+HEARTTM=(digits)<RET> set intval." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int  data;

		if( ptvar ){
			if( params.size() == 1 ){
				ss << params[ 0 ];
				ss >> data;

				ptvar->SetValue( "/net/socket/sock1/heart/heart_send_intval" , data );
				ptvar->SetValue( "/net/socket/sock2/heart/heart_send_intval" , data );
				ptvar->SetValue( "/net/socket/sock3/heart/heart_send_intval" , data );
				ptvar->SetValue( "/net/socket/sock4/heart/heart_send_intval" , data );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ss << AT_OK_STR << "+HEARTTM:" ;
				ptvar->GetValue( "/net/socket/sock1/heart/heart_send_intval" , data );
				ss << data << ",";
				ptvar->GetValue( "/net/socket/sock2/heart/heart_send_intval" , data );
				ss << data << ",";
				ptvar->GetValue( "/net/socket/sock3/heart/heart_send_intval" , data );
				ss << data << ",";
				ptvar->GetValue( "/net/socket/sock4/heart/heart_send_intval" , data );

				ss << data << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTTM" , item ));
}

void atInst :: init_htpen()
{
	stAtHash  item("AT\\+HTPEN(\\?|=(ON|OFF)){0,1}\\r" ,
		"Get set http request method." ,
		"AT+HTPEN[?]<RET> Get HTTP switch status.\nAT+HTPTP=(ON|OFF)<RET> Set HTTP Switch status." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str , tmp_str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){
			#if defined( __DEBUG__ )
				std::cout << "AT+HTPEN Param:" << params[ 0 ] << std::endl;
			#endif
				if( params[ 0 ].find("ON" ) != std::string::npos ){
					ptvar->SetValue( "/http/enable" , true );
					str = AT_OK_STR;
				}
				else if( params[ 0 ].find( "OFF") != std::string::npos ){
					ptvar->SetValue( "/http/enable" , false );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n"
					<< "Error enum value , should be ON or OFF.\r\n"
					<< "[FUNCTION]:" << m_at_hash["AT+HTPEN"].fun_desc << "\r\n"
					<< "[GRAMMA]:" << m_at_hash[ "AT+HTPEN" ] << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n"
				<< "Bad Command gramma."
				<< "[FUNCTION]:" << m_at_hash["AT+HTPEN"].fun_desc << "\r\n"
				<< "[GRAMMA]:" << m_at_hash[ "AT+HTPEN" ] << "\r\n";
				str = ss.str();
			}else{
				bool d = false;
				ptvar->GetValue( "/http/enable" , d );
				ss << AT_OK_STR << "+HTPEN:" << ( d == true ? "ON" : "OFF") << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPEN" , item ) );
}

void atInst::init_htptp()
{
	stAtHash  item("AT\\+HTPTP(\\?|=(GET|POST)){0,1}\\r" ,
			"Get set http request method." ,
			"AT+HTPTP[?]<RET> Get method.\nAT+HTPTP=(GET|POST)<RET> Set method" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str , tmp_str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "GET" || params[ 0 ] == "POST" ){
					ptvar->SetValue( "/http/method" , params[ 0 ] );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_UNSPORTED_HTP_MTD << "\r\n";
					str = ss.str();
				}
			}else if( params.size() > 1){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/http/method" , tmp_str );
				ss << AT_OK_STR << "+HTPTP:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPTP" , item ) );
}
void atInst::init_htpurl()
{
	stAtHash  item("AT\\+HTPURL(\\?|(=(\\w|\\W)+)){0,1}\\r" ,
			"Get or set http request URL." ,
			"AT+HTPURL[?]<RET> get url\nAT+HTPURL=(data)<RET> set url." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str , tmp_str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){
		#if defined( __DEBUG__ )
				std::cout << TRED << "SET URL AS:" << TYELLOW << params[ 0 ] << TNORMAL << std::endl;
		#endif
				ptvar->SetValue( "/http/url" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1){
				ss << "+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/http/url" , tmp_str );
				ss << AT_OK_STR << "+HTPURL:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPURL" , item ));
}

void atInst::init_htpsv()
{
	stAtHash  item("AT\\+HTPSV(\\?|=(\\w|\\.|-)+\\,[1-9]\\d{0,4}){0,1}\\r" ,
			"Get or set http server address, IP or DNS" ,
			"AT+HTPSV[?]<RET> get server parameters\nAT+HTPSV=(server),(port)<RET> set server parameters" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str , tmp_str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 2 ){
				ptvar->SetValue( "/http/server" , params[ 0 ] );
				ptvar->SetValue( "/http/port" , params[ 1 ] );
				str = AT_OK_STR;
			}else if( params.size() > 2){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/http/server" , tmp_str );
				long port;
				ptvar->GetValue( "/http/port" , port );
				ss << AT_OK_STR << "+HTPSV:" << tmp_str << "," << port << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPSV" , item ));
}

void atInst::init_htphd()
{
    	stAtHash  item("AT\\+HTPHD(\\?|=(\\w|\\W)+){0,1}\\r" ,
                   "Get or set HTTP head." ,
                   "AT+HTPHD[?]<RET> Get head info.\nAT+HTPHD=(data)<RET> Set head information." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/http/head" , params[ 0 ] );
				str = at + AT_OK_STR;

			}else if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				std::string tmp_str;
				ptvar->GetValue( "/http/head" , tmp_str );

				ss << AT_OK_STR << "+HTPHD:" << tmp_str << "\r\n";

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();

			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPHD" , item ) );
}

void atInst::init_htpto()
{
	stAtHash  item("AT\\+HTPTO(\\?{0,1}|=[1-6]\\d{0,2})\\r" ,
			"Get or set HTTP request overtime, between 1~600s" ,
			"AT+HTPTO[?]<RET> get overtime;\nAT+HTPTO=(digit)<RET> set overtime" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int overtime;

		if( ptvar ){
			if( params.size() == 1 ){
				ss << params[ 0 ];
				ss >> overtime;
				if( overtime > 0 && overtime <= 600 ){
					ptvar->SetValue( "/http/overtime" , overtime );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR" << ERR_BAD_GRAMMA << "\r\n"
					<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
					<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
					str = ss.str();
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/http/port" , overtime );
				ss << AT_OK_STR << "+HTPTO:" << overtime << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n"
			<< "[FUNCTION]:" << m_at_hash["AT+HTPTO"].fun_desc << "\r\n"
			<< "[GRAMMA]:" << m_at_hash["AT+HTPTO"].err_msg << "\r\n";
			str = ss.str();
		}

		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPTO" , item ));
}
void atInst::init_htpflt()
{
	stAtHash  item("AT+HTPFLT(\\?|=(ON|OFF)){0,1}\\r" ,
			"get or set head infomation filter switch status" ,
			"AT+HTPFLT[?]<RET> get status;\nAT+HTPFLT=(ON|OFF)<RET> set status" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int overtime;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ss << params[ 0 ];
				ss >> overtime;

				ptvar->SetValue( "/http/overtime" , overtime );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/http/port" , overtime );
				ss << AT_OK_STR << "+HTPTO:" << overtime << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPFLT" , item ));
}

void atInst::init_smsend()
{//\\W|\\w|\\s|[\\u4e00-\\ufefe]
	stAtHash  item( "AT\\+SMSEND(\\?|=\\+{0,1}\\d{11,14}\\,(\\W|\\w|\\s|[\\x80-\\xff])+){0,1}\\r" , 
			"" , 
			"" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;

		if( params.size() == 2 ){
			std::string  phone = params[ 0 ], msg;
			sms * ptsms = GetSMSHandle();
			if( ptsms ){
				sms::sms_type type = sms::GSM_7BIT;
				msg = params[ 1 ];
				for( size_t i = 0 ; i < params[ 1 ].length(); i ++ ){
					if( msg.at( i ) > 0x7F ){
						type = sms::UCS2;
						break;
					}
				}
				size_t rst = ptsms->send( phone , msg , type );
				if( rst > 0 ) str = AT_OK_STR;
				else{
					ss << "\r\n+ERR:" << ERR_SMS_SEND_FAIL << "\r\n";
					str = std::move( ss.str() );
				}
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_SMS_OBJ << "\r\n";
				str = std::move( ss.str() );
			}

		}else{
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SMSEND" , item ));
}
void atInst::init_cismssend()
{
	stAtHash  item("AT\\+CISMSEND(\\?|=\\+{0,1}\\d{11,14}\\,(\\W|\\w|\\s|[\u8140-\ufefe])+){0,1}\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
			std::string str;
		std::stringstream ss;

		if( params.size() == 2 ){
			std::string  phone = params[ 0 ], msg;
			sms * ptsms = GetSMSHandle();
			if( ptsms ){
				sms::sms_type type = sms::GSM_7BIT;
				msg = params[ 1 ];
				for( size_t i = 0 ; i < params[ 1 ].length(); i ++ ){
					if( msg.at( i ) > 0x7F ){
						type = sms::UCS2;
						break;
					}
				}
				ptsms->send( phone , msg , type );
				str = AT_OK_STR;
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_SMS_OBJ << "\r\n";
				str = std::move( ss.str() );
			}

		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CISMSEND" , item ));
}

void atInst::init_hz()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HZ" , item ));
}
void atInst::init_reset()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+RESET" , item ));
}
void atInst::init_sockadd()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKADD" , item ));
}
void atInst::init_sock()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this]( const std::string& at , const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCK" , item ));
}
void atInst::init_sockdel()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SOCKDEL" , item ));
}
void atInst::init_ping()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+PING" , item ));
}
void atInst::init_ca()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CA" , item ));
}
void atInst::init_cer()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CER" , item ));
}
void atInst::init_mqttsvr()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MQTTSVR" , item ));
}
void atInst::init_mqttuser()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at , const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MQTTUSER" , item ));
}
void atInst::init_mqtttpc()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MQTTPC" , item ));
}
void atInst::init_mqttsnd()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MQTTSND" , item ));
}
void atInst::init_mqttunsub()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MQTTUNSUB" , item ));
}

void atInst::init_kd()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+KD" , item ));
}
void atInst::init_comd()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+COMD" , item ));
}
void atInst::init_netd()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+NETD" , item ));
}

void atInst::init_ssl()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+SSL" , item ));
}
void atInst::init_htps()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HTPS" , item ));
}
void atInst::init_crypto()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+CRYPTO" , item ));
}
void atInst::init_zip()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+ZIP" , item ));
}
void atInst::init_filter()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+FILTER" , item ));
}
void atInst::init_report()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REPORT" , item ));
}
void atInst::init_rmset()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+RMSET" , item ));
}
void atInst::init_rmta()
{
	stAtHash  item("AT\\+CISMSEND(\\?{0,1}|=\\+{0,1}\\d{11,14}\\,.+)\\r" , "" , "" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		if( params.size() > 0 ){

		}else{

		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+RMTA" , item ));
}

void atInst :: init_save()
{
	stAtHash item( "AT\\+S\\r" , "" , "" );

	item.fun = [ this ]( const std::string& at , const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		if( params.size() != 0 ){
            		ss.clear(); ss.str();
            		ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
            		str = std::move( ss.str() );
		}else{
			std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			if( ptvar ){
				ptvar->Save( "/data/sndtu/config.xml" );
				str = AT_OK_STR + "\r\nDevice will restart.\r\n";
			}else{
				ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
				str = ss.str();
			}
		}
		response( at , str );
		sync();
		std::thread thd([]{	// 延迟1秒后重启设备
			std::this_thread::yield();
			std::this_thread::sleep_for( std::chrono::seconds( 1 ));
			abort();
		});
		thd.detach();
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+S" , item ) );
}

void atInst :: init_hearttm_a()
{
	stAtHash  item("AT\\+HEARTTMA(\\?|=[1-6]\\d{0,3}){0,1}\\r" ,
                   "Get or set socket A heart package send intval, between 1~60000s" ,
                   "AT+HEARTTMA[?]<RET> Get interval.\nAT+HEARTTMA=(digits)<RET> set interval." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int  data;

		if( ptvar ){
			if( params.size() == 1 ){
				ss << params[ 0 ];
				ss >> data;

				ptvar->SetValue( "/net/socket/sock1/heart/heart_send_intval" , data );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock1/heart/heart_send_intval" , data );

				ss << AT_OK_STR << "+HEARTTMA:" << data << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTTMA" , item ));
}
void atInst :: init_hearttm_b()
{
	stAtHash  item("AT\\+HEARTTMB(\\?|=[1-6]\\d{0,3}){0,1}\\r" ,
                   "Get or set socket B heart package send intval, between 1~60000s" ,
                   "AT+HEARTTMB[?]<RET> Get intval.\nAT+HEARTTMB=(digits)<RET> set intval." );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int  data;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ss << params[ 0 ];
				ss >> data;
				ptvar->SetValue( "/net/socket/sock2/heart/heart_send_intval" , data );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock2/heart/heart_send_intval" , data );

				ss << AT_OK_STR << "+HEARTTMB:" << data << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTTMB" , item ));
}
void atInst :: init_hearttm_c()
{
	stAtHash  item("AT\\+HEARTTMC(\\?|=[1-6]\\d{0,3}){0,1}\\r" ,
                   "Get or set socket C heart package send intval, between 1~60000s" ,
                   "AT+HEARTTMC[?]<RET> Get intval.\nAT+HEARTTMC=(digits)<RET> set intval." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int  data;

		if( ptvar ){
		if( params.size() == 1 ){
			ss << params[ 0 ];
			ss >> data;

			ptvar->SetValue( "/net/socket/sock3/heart/heart_send_intval" , data );

			str = AT_OK_STR;
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			ptvar->GetValue( "/net/socket/sock3/heart/heart_send_intval" , data );

			ss << AT_OK_STR << "+HEARTTMC:" << data << "\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    };

    m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTTMC" , item ));
}
void atInst :: init_hearttm_d()
{
	stAtHash  item("AT\\+HEARTTMD(\\?|=[1-6]\\d{0,3}){0,1}\\r" ,
                   "Get or set socket D heart package send intval, between 1~60000s" ,
                   "AT+HEARTTMD[?]<RET> Get intval.\nAT+HEARTTMD=(digits)<RET> set intval." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string str;
		std::stringstream ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		int  data;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ss << params[ 0 ];
				ss >> data;

				ptvar->SetValue( "/net/socket/sock4/heart/heart_send_intval" , data );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock4/heart/heart_send_intval" , data );

				ss << AT_OK_STR << "+HEARTTMD:" << data << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTTMD" , item ));
}

void atInst :: init_heartsnd_a()
{
	stAtHash  item("AT\\+HEARTSNDA(\\?|=(COM|NET)){0,1}\\r" ,
                   "Get or set socket A heart send direction." ,
                   "AT+HEARTSNDA[?]<RET> Get heart send direction.\n AT+HEARTSNDA=(COM|NET)<RET> Set heart send direction." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                 str , tmp_str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream 			ss;
			
		if( ptvar ){
		if( params.size() == 1 ){
			ptvar->SetValue( "/net/socket/sock1/heart/heart_send_dir" , params[ 0 ] );

			str = AT_OK_STR;
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			ptvar->GetValue( "/net/socket/sock1/heart/heart_send_dir" , tmp_str );
			ss << AT_OK_STR << "+HEARTSNDA:" << tmp_str << "\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTSNDA" , item ));
}
void atInst :: init_heartsnd_b()
{
	stAtHash  item("AT\\+HEARTSNDB(\\?|=(COM|NET)){0,1}\\r" ,
                   "Get or set socket B heart send direction." ,
                   "AT+HEARTSNDB[?]<RET> Get heart send direction.\n AT+HEARTSNDB=(COM|NET)<RET> Set heart send direction." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                 str , tmp_str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream 			ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock2/heart/heart_send_dir" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock2/heart/heart_send_dir" , tmp_str );
				ss << AT_OK_STR << "+HEARTSNDB:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTSNDB" , item ));
}
void atInst :: init_heartsnd_c()
{
	stAtHash  item("AT\\+HEARTSNDC(\\?|=(COM|NET)){0,1}\\r" ,
                   "Get or set socket C heart send direction." ,
                   "AT+HEARTSNDC[?]<RET> Get heart send direction.\n AT+HEARTSNDC=(COM|NET)<RET> Set heart send direction." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                 str , tmp_str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream 			ss;
			
		if( ptvar ){
			if( params.size() == 1 ){

				ptvar->SetValue( "/net/socket/sock3/heart/heart_send_dir" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock3/heart/heart_send_dir" , tmp_str );
				ss << AT_OK_STR << "+HEARTSNDC:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTSNDC" , item ));
}
void atInst :: init_heartsnd_d()
{
	stAtHash  item("AT\\+HEARTSNDD(\\?|=(COM|NET)){0,1}\\r" ,
                   "Get or set socket D heart send direction." ,
                   "AT+HEARTSNDD[?]<RET> Get heart send direction.\n AT+HEARTSNDD=(COM|NET)<RET> Set heart send direction." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                 str , tmp_str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream 			ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock4/heart/heart_send_dir" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock4/heart/heart_send_dir" , tmp_str );
				ss << AT_OK_STR << "+HEARTSNDD:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTSNDD" , item ));
}

void atInst :: init_heartdt_a()
{
	stAtHash  item("AT\\+HEARTDTA(\\?|=(\\w|\\.|-|_|\\*|#|\\$|@|\\&)+){0,1}\\r" ,
                   "Get or set socket A heart package data." ,
                   "AT+HEARTDTA[?]<RET> get data.\nAT+HEARTDTA=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str , tmp_str;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		std::stringstream          ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock1/heart/data" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock1/heart/data" , str );
				ss << AT_OK_STR << "+HEARTDTA:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTDTA" , item ) );
}
void atInst :: init_heartdt_b()
{
	stAtHash  item("AT\\+HEARTDTB(\\?|=(\\w|\\.|-|_|\\*|#|\\$|@|\\&)+){0,1}\\r" ,
                   "Get or set socket B heart package data." ,
                   "AT+HEARTDTB[?]<RET> get data.\nAT+HEARTDTB=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str , tmp_str;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		std::stringstream          ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock2/heart/data" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock2/heart/data" , str );
				ss << AT_OK_STR << "+HEARTDTB:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTDTB" , item ) );
}
void atInst :: init_heartdt_c()
{
	stAtHash  item("AT\\+HEARTDTC(\\?|=(\\w|\\.|-|_|\\*|#|\\$|@|\\&)+){0,1}\\r" ,
                   "Get or set socket C heart package data." ,
                   "AT+HEARTDTC[?]<RET> get data.\nAT+HEARTDTC=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str , tmp_str;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		std::stringstream          ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock3/heart/data" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock3/heart/data" , str );
				ss << AT_OK_STR << "+HEARTDTC:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTDTC" , item ) );
}
void atInst :: init_heartdt_d()
{
	stAtHash  item("AT\\+HEARTDTD(\\?|=(\\w|\\.|-|_|\\*|#|\\$|@|\\&)+){0,1}\\r" ,
                   "Get or set socket D heart package data." ,
                   "AT+HEARTDTD[?]<RET> get data.\nAT+HEARTDTD=(data)<RET> Set data." );

    item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str , tmp_str;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		std::stringstream          ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock4/heart/data" , params[ 0 ] );

				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock4/heart/data" , str );
				ss << AT_OK_STR << "+HEARTDTD:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTDTD" , item ) );
}

void atInst :: init_hearten_a()
{
	stAtHash  item("AT\\+HEARTENA(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket A heart package switch status." ,
                   "AT+HEARTENA[?]<RET> Get status.\n AT+HEARTENA=(ON|OFF)<RET> Set status" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		bool                       en = false;
			
		if( ptvar ){
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() ) ){
				case hash_compile_time( "ON" ):
				ptvar->SetValue( "/net/socket/sock1/heart/enable" , true );
				str = AT_OK_STR;
				break;
				case hash_compile_time( "OFF" ):
				ptvar->SetValue( "/net/socket/sock1/heart/enable" , false );
				str = AT_OK_STR;
				break;
				default:
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
				break;
				}

			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue("/net/socket/sock1/heart/enable" , en );
				if( en ){
					ss << AT_OK_STR << "+HEARTENA:ON\r\n";
				}else{
					ss << AT_OK_STR << "+HEARTENA:OFF\r\n";
				}

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTENA" , item ) );
}
void atInst :: init_hearten_b()
{
	stAtHash  item("AT\\+HEARTENB(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket B heart package switch status." ,
                   "AT+HEARTENB[?]<RET> Get status.\n AT+HEARTENB=(ON|OFF)<RET> Set status" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		bool                       en = false;
			
		if( ptvar ){
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() ) ){
				case hash_compile_time( "ON" ):
				ptvar->SetValue( "/net/socket/sock2/heart/enable" , true );
				str = AT_OK_STR;
				break;
				case hash_compile_time( "OFF" ):
				ptvar->SetValue( "/net/socket/sock2/heart/enable" , false );
				str = AT_OK_STR;
				break;
				default:
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
				break;
				}

			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue("/net/socket/sock2/heart/enable" , en );
				if( en ){
					ss << AT_OK_STR << "+HEARTENB:ON\r\n";
				}else{
					ss << AT_OK_STR << "+HEARTENB:OFF\r\n";
				}

				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTENB" , item ) );
}
void atInst :: init_hearten_c()
{
	stAtHash  item("AT\\+HEARTENC(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket C heart package switch status." ,
                   "AT+HEARTENC[?]<RET> Get status.\n AT+HEARTENC=(ON|OFF)<RET> Set status" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		bool                       en = false;
			
		if( ptvar ){
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() ) ){
				case hash_compile_time( "ON" ):
				ptvar->SetValue( "/net/socket/sock3/heart/enable" , true );
				str = AT_OK_STR;
				break;
				case hash_compile_time( "OFF" ):
				ptvar->SetValue( "/net/socket/sock3/heart/enable" , false );
				str = AT_OK_STR;
				break;
				default:
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
				break;
				}

			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue("/net/socket/sock3/heart/enable" , en );
				if( en ){
					ss << AT_OK_STR << "+HEARTENC:ON\r\n";
				}else{
					ss << AT_OK_STR << "+HEARTENC:OFF\r\n";
				}

				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTENC" , item ) );
}
void atInst :: init_hearten_d()
{
	stAtHash  item("AT\\+HEARTEND(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket D heart package switch status." ,
                   "AT+HEARTEND[?]<RET> Get status.\n AT+HEARTEND=(ON|OFF)<RET> Set status" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string                str;
		std::stringstream          ss;
		std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
		bool                       en = false;
			
		if( ptvar ){
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() ) ){
				case hash_compile_time( "ON" ):
				ptvar->SetValue( "/net/socket/sock4/heart/enable" , true );
				str = AT_OK_STR;
				break;
				case hash_compile_time( "OFF" ):
				ptvar->SetValue( "/net/socket/sock4/heart/enable" , false );
				str = AT_OK_STR;
				break;
				default:
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
				break;
				}

			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				ptvar->GetValue("/net/socket/sock4/heart/enable" , en );
				if( en ){
					ss << AT_OK_STR << "+HEARTEND:ON\r\n";
				}else{
					ss << AT_OK_STR << "+HEARTEND:OFF\r\n";
				}

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTEND" , item ) );
}

void atInst :: init_regdt_a()
{
	stAtHash  item("AT\\+REGDTA(\\?|=(\\w|\\W)+){0,1}\\r" ,
                   "Get or set SOCKET A register package data." ,
                   "AT+REGDTA[?]<RET> Get data.\nAT+REGDTA=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 				str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;

		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock1/reg/data" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\nNeed one parameter but got more.\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock1/reg/data" , str );
				ss << AT_OK_STR << "+REGDTA:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
			response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGDTA" , item ) );
}

void atInst :: init_regdt_b()
{
	stAtHash  item("AT\\+REGDTB(\\?|=(\\w|\\W)+){0,1}\\r" ,
                   "Get or set SOCKET B register package data." ,
                   "AT+REGDTB[?]<RET> Get data.\nAT+REGDTB=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 				str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock2/reg/data" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\nNeed one parameter but got more.\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock2/reg/data" , str );
				ss << AT_OK_STR << "+REGDTB:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGDTB" , item ) );
}
void atInst :: init_regdt_c()
{
	stAtHash  item("AT\\+REGDTC(\\?|=(\\w|\\W)+){0,1}\\r" ,
                   "Get or set SOCKET C register package data." ,
                   "AT+REGDTC[?]<RET> Get data.\nAT+REGDTC=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 				str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock3/reg/data" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock3/reg/data" , str );
				ss << AT_OK_STR << "+REGDTC:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGDTC" , item ) );
}
void atInst :: init_regdt_d()
{
	stAtHash  item("AT\\+REGDTD(\\?|=(\\w|\\W)+){0,1}\\r" ,
                   "Get or set SOCKET D register package data." ,
                   "AT+REGDTD[?]<RET> Get data.\nAT+REGDTD=(data)<RET> Set data." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 				str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				ptvar->SetValue( "/net/socket/sock4/reg/data" , params[ 0 ] );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				ptvar->GetValue( "/net/socket/sock4/reg/data" , str );
				ss << AT_OK_STR << "+REGDTD:" << str << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGDTD" , item ) );
}

void atInst :: init_regsnd_a()
{
	stAtHash  item("AT\\+REGSNDA(\\?|=(LINK|DATA|BOTH)){0,1}\\r" ,
                   "Get or set socket A register package send type." ,
                   "AT+REGSNDA[?]<RET> Get send type.\nAT+REGSENDA=(LINK|DATA|BOTH)<RET> Set send type" );

	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 		    str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				bool flag = false;
				flag = false;
				switch( hash_( params[ 0 ].c_str() ) ){
				case hash_compile_time( "LINK" ): flag = true; break;
				case hash_compile_time( "DATA" ): flag = true; break;
						case hash_compile_time( "BOTH" ): flag = true; break;
				default: flag = false;  break;
				}

				if( flag == true ){
					ptvar->SetValue( "/net/socket/sock1/reg/type" , params[ 0 ] );
					str = AT_OK_STR;
				}else{// 可选项错误
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
					str = ss.str();
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock1/reg/type" , str );
				ss << AT_OK_STR << "+REGSNDA:" << str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
	};

        m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGSNDA" , item ) );
}
void atInst :: init_regsnd_b()
{
	stAtHash  item("AT\\+REGSNDB(\\?|=(LINK|DATA|BOTH)){0,1}\\r" ,
                   "Get or set socket B register package send type." ,
                   "AT+REGSNDB[?]<RET> Get send type.\nAT+REGSENDB=(LINK|DATA|BOTH)<RET> Set send type" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 		    str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
		if( params.size() == 1 ){
			bool flag = false;
			flag = false;
			switch( hash_( params[ 0 ].c_str() ) ){
			case hash_compile_time( "LINK" ): flag = true; break;
			case hash_compile_time( "DATA" ): flag = true; break;
					case hash_compile_time( "BOTH" ): flag = true; break;
			default: flag = false;  break;
			}

			if( flag == true ){
				ptvar->SetValue( "/net/socket/sock2/reg/type" , params[ 0 ] );
				str = AT_OK_STR;
			}else{// 可选项错误
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			ptvar->GetValue( "/net/socket/sock2/reg/type" , str );
			ss << AT_OK_STR << "+REGSNDB:" << str << "\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

        m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGSNDB" , item ) );
}
void atInst :: init_regsnd_c()
{
	stAtHash  item("AT\\+REGSNDC(\\?|=(LINK|DATA|BOTH)){0,1}\\r" ,
                   "Get or set socket C register package send type." ,
                   "AT+REGSNDC[?]<RET> Get send type.\nAT+REGSENDC=(LINK|DATA|BOTH)<RET> Set send type" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 		    str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
		if( params.size() == 1 ){
			bool flag = false;
			flag = false;
			switch( hash_( params[ 0 ].c_str() ) ){
			case hash_compile_time( "LINK" ): flag = true; break;
			case hash_compile_time( "DATA" ): flag = true; break;
					case hash_compile_time( "BOTH" ): flag = true; break;
			default: flag = false;  break;
			}

			if( flag == true ){
				ptvar->SetValue( "/net/socket/sock3/reg/type" , params[ 0 ] );
				str = AT_OK_STR;
			}else{// 可选项错误
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			ptvar->GetValue( "/net/socket/sock3/reg/type" , str );
			ss << AT_OK_STR << "+REGSNDC:" << str << "\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

        m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGSNDC" , item ) );
}
void atInst :: init_regsnd_d()
{
	stAtHash  item("AT\\+REGSNDD(\\?|=(LINK|DATA|BOTH)){0,1}\\r" ,
                   "Get or set socket D register package send type." ,
                   "AT+REGSNDD[?]<RET> Get send type.\nAT+REGSENDD=(LINK|DATA|BOTH)<RET> Set send type" );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::string 		    str;
		std::shared_ptr< CSysVar >  ptvar = GetOrCreateSysVar();
		std::stringstream           ss;
			
		if( ptvar ){
			if( params.size() == 1 ){
				bool flag = false;
				flag = false;
				switch( hash_( params[ 0 ].c_str() ) ){
				case hash_compile_time( "LINK" ): flag = true; break;
				case hash_compile_time( "DATA" ): flag = true; break;
						case hash_compile_time( "BOTH" ): flag = true; break;
				default: flag = false;  break;
				}

				if( flag == true ){
					ptvar->SetValue( "/net/socket/sock4/reg/type" , params[ 0 ] );
					str = AT_OK_STR;
				}else{// 可选项错误
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				ptvar->GetValue( "/net/socket/sock4/reg/type" , str );
				ss << AT_OK_STR << "+REGSNDD:" << str << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

        m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGSNDD" , item ) );
}

void atInst :: init_regtp_a()
{
	stAtHash  item("AT\\+REGTPA(\\?|=(ICCID|IMEI|CLOUD|USER)){0,1}\\r" ,
                   "Get or set socket A register package content type." ,
                   "AT+REGTPA[?]<RET> Get type.\nAT+REGTPA=(type)<REG> set type." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		std::string str , tmp_str;
		std::stringstream  ss;
			
		if( ptvar ){
		bool flag = false;
		if( params.size() == 1 ){
			switch( hash_( params[ 0 ].c_str() )){
				case hash_compile_time( "ICCID" ): case hash_compile_time ( "IMEI" ):
				case hash_compile_time( "CLOUD" ): case hash_compile_time ( "USER" ):
				flag = true;                    break;
				default:flag = false; break;
			}

			if( flag ){
				ptvar->SetValue( "/net/socket/sock1/reg/data_type" , params[ 0 ] );
				str = AT_OK_STR;
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
				str = std::move( ss.str() );
			}


		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{
			ptvar->GetValue( "/net/socket/sock1/reg/data_type" , tmp_str );
			ss << AT_OK_STR << "+REGTPA:" << tmp_str << "\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

    m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGTPA" , item ) );
}
void atInst :: init_regtp_b()
{
	stAtHash  item("AT\\+REGTPB(\\?|=(ICCID|IMEI|CLOUD|USER)){0,1}\\r" ,
                   "Get or set socket B register package content type." ,
                   "AT+REGTPB[?]<RET> Get type.\nAT+REGTPB=(type)<REG> set type." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		std::string str , tmp_str;
		std::stringstream  ss;
			
		if( ptvar ){
		bool flag = false;
		if( params.size() == 1 ){
			switch( hash_( params[ 0 ].c_str() )){
				case hash_compile_time( "ICCID" ): case hash_compile_time ( "IMEI" ):
				case hash_compile_time( "CLOUD" ): case hash_compile_time ( "USER" ):
				flag = true;                    break;
				default:flag = false; break;
			}

			if( flag ){
				ptvar->SetValue( "/net/socket/sock2/reg/data_type" , params[ 0 ] );
				str = AT_OK_STR;
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
				str = ss.str();
			}


		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{
			ptvar->GetValue( "/net/socket/sock2/reg/data_type" , tmp_str );
			ss << AT_OK_STR << "+REGTPB:" << tmp_str << "\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGTPB" , item ) );
}
void atInst :: init_regtp_c()
{
	stAtHash  item("AT\\+REGTPC(\\?|=(ICCID|IMEI|CLOUD|USER)){0,1}\\r" ,
                   "Get or set socket C register package content type." ,
                   "AT+REGTPC[?]<RET> Get type.\nAT+REGTPC=(type)<REG> set type." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		std::string str , tmp_str;
		std::stringstream  ss;
			
		if( ptvar ){
			bool flag = false;
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() )){
				case hash_compile_time( "ICCID" ): case hash_compile_time ( "IMEI" ):
				case hash_compile_time( "CLOUD" ): case hash_compile_time ( "USER" ):
				flag = true;                    break;
				default:flag = false; break;
				}

				if( flag ){
					ptvar->SetValue( "/net/socket/sock3/reg/data_type" , params[ 0 ] );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
					str = ss.str();
				}


			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock3/reg/data_type" , tmp_str );
				ss << AT_OK_STR << "+REGTPC:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGTPC" , item ) );
}
void atInst :: init_regtp_d()
{
	stAtHash  item("AT\\+REGTPD(\\?|=(ICCID|IMEI|CLOUD|USER)){0,1}\\r" ,
                   "Get or set socket D register package content type." ,
                   "AT+REGTPD[?]<RET> Get type.\nAT+REGTPD=(type)<REG> set type." );

    	item.fun = [this](const std::string& at ,const ArrayString& params ){
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		std::string str , tmp_str;
		std::stringstream  ss;
			
		if( ptvar ){
			bool flag = false;
			if( params.size() == 1 ){
				switch( hash_( params[ 0 ].c_str() )){
				case hash_compile_time( "ICCID" ): case hash_compile_time ( "IMEI" ):
				case hash_compile_time( "CLOUD" ): case hash_compile_time ( "USER" ):
				flag = true;                    break;
				default:flag = false; break;
				}

				if( flag ){
					ptvar->SetValue( "/net/socket/sock4/reg/data_type" , params[ 0 ] );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
					str = ss.str();
				}


			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				ptvar->GetValue( "/net/socket/sock4/reg/data_type" , tmp_str );
				ss << AT_OK_STR << "+REGTPD:" << tmp_str << "\r\n";
				str = ss.str();
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGTPD" , item ) );
}

void atInst :: init_regen_a()
{
	stAtHash  item("AT\\+REGENA(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket A register package switch status." ,
                   "AT+REGENA[?]<RET> Get status;\nAT+REGENA=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		bool                     en = false;
			
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ] == "ON" ){
				ptvar->SetValue( "/net/socket/sock1/reg/enable" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ] == "OFF" ){
				ptvar->SetValue( "/net/socket/sock1/reg/enable" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{// 查询
			ptvar->GetValue( "/net/socket/sock1/reg/enable" , en );
			if( en )
				ss << AT_OK_STR << "+REGENA:ON\r\n";
			else
				ss << AT_OK_STR << "+REGENA:OFF\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGENA" , item ) );
}
void atInst :: init_regen_b()
{
	stAtHash  item("AT\\+REGENB(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set register package switch status." ,
                   "AT+REGENB[?]<RET> Get status;\nAT+REGENB=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		bool                     en = false;
			
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ] == "ON" ){
				ptvar->SetValue( "/net/socket/sock2/reg/enable" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ] == "OFF" ){
				ptvar->SetValue( "/net/socket/sock2/reg/enable" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = ss.str();
		}else{// 查询
			ptvar->GetValue( "/net/socket/sock2/reg/enable" , en );
			if( en )
				ss << AT_OK_STR << "+REGENB:ON\r\n";
			else
				ss << AT_OK_STR << "+REGENB:OFF\r\n";
			str = ss.str();
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = ss.str();
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGENB" , item ) );
}
void atInst :: init_regen_c()
{
	stAtHash  item("AT\\+REGENC(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket B register package switch status." ,
                   "AT+REGENC[?]<RET> Get status;\nAT+REGENC=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		bool                     en = false;
		
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ] == "ON" ){
					ptvar->SetValue( "/net/socket/sock3/reg/enable" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ] == "OFF" ){
					ptvar->SetValue( "/net/socket/sock3/reg/enable" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
				ptvar->GetValue( "/net/socket/sock3/reg/enable" , en );
				if( en )
					ss << AT_OK_STR << "+REGENC:ON\r\n";
				else
					ss << AT_OK_STR << "+REGENC:OFF\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGENC" , item ) );
}

void atInst :: init_regen_d()
{
	stAtHash  item("AT\\+REGEND(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket D register package switch status." ,
                   "AT+REGEND[?]<RET> Get status;\nAT+REGEND=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ] == "ON" ){
				ptvar->SetValue( "/net/socket/sock4/reg/enable" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ] == "OFF" ){
				ptvar->SetValue( "/net/socket/sock4/reg/enable" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{// 查询
			bool en = false;
			ptvar->GetValue( "/net/socket/sock4/reg/enable" , en );
			if( en )
				ss << AT_OK_STR << "+REGEND:ON\r\n";
			else
				ss << AT_OK_STR << "+REGEND:OFF\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGEND" , item ) );
}

void atInst :: init_reghex_en()
{
	stAtHash  item("AT\\+REGHEXEN(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket register package HEX switch status." ,
                   "AT+REGHEXEN[?]<RET> Get status;\nAT+REGHEXEN=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ].find("ON") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock1/reg/hex" , true );
				ptvar->SetValue( "/net/socket/sock2/reg/hex" , true );
				ptvar->SetValue( "/net/socket/sock3/reg/hex" , true );
				ptvar->SetValue( "/net/socket/sock4/reg/hex" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ].find("OFF") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock1/reg/hex" , false );
				ptvar->SetValue( "/net/socket/sock2/reg/hex" , false );
				ptvar->SetValue( "/net/socket/sock3/reg/hex" , false );
				ptvar->SetValue( "/net/socket/sock4/reg/hex" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{// 查询
			bool en1 = false, en2 = false , en3 = false , en4 = false;
			ptvar->GetValue( "/net/socket/sock1/reg/hex" , en1 );
			ptvar->GetValue( "/net/socket/sock2/reg/hex" , en2 );
			ptvar->GetValue( "/net/socket/sock3/reg/hex" , en3 );
			ptvar->GetValue( "/net/socket/sock4/reg/hex" , en4 );
			
			ss << AT_OK_STR << "+REGHEXEN:" << ( en1 == true ? "ON" : "OFF") 
						<< ( en2 == true ? ",ON":",OFF")
						<< ( en3 == true ? ",ON":",OFF")
						<< ( en4 == true ? ",ON":",OFF") << "\r\n";
			
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	// 添加操作映射
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGHEXEN" , item ) );
}

void atInst :: init_reghex_ena()
{
	stAtHash  item("AT\\+REGHEXENA(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket A register package HEX switch status." ,
                   "AT+REGHEXENA[?]<RET> Get status;\nAT+REGHEXENA=(ON|OFF) set status." );

   	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ].find("ON") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock1/reg/hex" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find("OFF") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock1/reg/hex" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
						bool en = false;
				ptvar->GetValue( "/net/socket/sock1/reg/hex" , en );
				if( en )
					ss << AT_OK_STR << "+REGHEXENA:ON\r\n";
				else
					ss << AT_OK_STR << "+REGHEXENA:OFF\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGHEXENA" , item ) );
}

void atInst :: init_reghex_enb()
{
	stAtHash  item("AT\\+REGHEXENB(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket B register package HEX switch status." ,
                   "AT+REGHEXENB[?]<RET> Get status;\nAT+REGHEXENB=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ].find("ON") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock2/reg/hex" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ].find("OFF") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock2/reg/hex" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{// 查询
			bool en = false;
			ptvar->GetValue( "/net/socket/sock2/reg/hex" , en );
			if( en )
				ss << AT_OK_STR << "+REGHEXENB:ON\r\n";
			else
				ss << AT_OK_STR << "+REGHEXENB:OFF\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGHEXENB" , item ) );
}

void atInst :: init_reghex_enc()
{
	stAtHash  item("AT\\+REGHEXENC(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket C register package HEX switch status." ,
                   "AT+REGHEXENC[?]<RET> Get status;\nAT+REGHEXENC=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
			
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ].find("ON") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock3/reg/hex" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find("OFF") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock3/reg/hex" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
						bool en = false;
				ptvar->GetValue( "/net/socket/sock3/reg/hex" , en );
				if( en )
				ss << AT_OK_STR << "+REGHEXENC:ON\r\n";
				else
				ss << AT_OK_STR << "+REGHEXENC:OFF\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGHEXENC" , item ) );
}

void atInst :: init_reghex_end()
{
	stAtHash  item("AT\\+REGHEXEND(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket D register package HEX switch status." ,
                   "AT+REGHEXEND[?]<RET> Get status;\nAT+REGHEXEND=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
			
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ].find("ON") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock4/reg/hex" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ].find("OFF") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock4/reg/hex" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{// 查询
					bool en = false;
			ptvar->GetValue( "/net/socket/sock4/reg/hex" , en );
			if( en )
				ss << AT_OK_STR << "+REGHEXEND:ON\r\n";
			else
				ss << AT_OK_STR << "+REGHEXEND:OFF\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+REGHEXEND" , item ) );
}

void atInst :: init_heart_hex()
{
	stAtHash  item("AT\\+HEARTHEXEN(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket heart package HEX switch status." ,
                   "AT+HEARTHEXEN[?]<RET> Get status;\nAT+HEARTHEXEN=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ].find("ON") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock1/heart/hex" , true );
					ptvar->SetValue( "/net/socket/sock2/heart/hex" , true );
					ptvar->SetValue( "/net/socket/sock3/heart/hex" , true );
					ptvar->SetValue( "/net/socket/sock4/heart/hex" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find("OFF") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock1/heart/hex" , false );
					ptvar->SetValue( "/net/socket/sock2/heart/hex" , false );
					ptvar->SetValue( "/net/socket/sock3/heart/hex" , false );
					ptvar->SetValue( "/net/socket/sock4/heart/hex" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
				bool en1 = false, en2 = false , en3 = false , en4 = false;
				ptvar->GetValue( "/net/socket/sock1/heart/hex" , en1 );
				ptvar->GetValue( "/net/socket/sock2/heart/hex" , en2 );
				ptvar->GetValue( "/net/socket/sock3/heart/hex" , en3 );
				ptvar->GetValue( "/net/socket/sock4/heart/hex" , en4 );
				
				ss << AT_OK_STR << "+HEARTHEXEN:" << ( en1 == true ? "ON" : "OFF") 
							<< ( en2 == true ? ",ON":",OFF")
							<< ( en3 == true ? ",ON":",OFF")
							<< ( en4 == true ? ",ON":",OFF") << "\r\n";
				
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	// 添加操作映射
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTHEXEN" , item ) );
}
void atInst :: init_heart_hexa()
{
	stAtHash  item("AT\\+HEARTHEXENA(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket A heart package HEX switch status." ,
                   "AT+HEARTHEXENA[?]<RET> Get status;\nAT+HEARTHEXENA=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ].find("ON") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock1/heart/hex" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find("OFF") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock1/heart/hex" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
						bool en = false;
				ptvar->GetValue( "/net/socket/sock1/heart/hex" , en );
				if( en )
					ss << AT_OK_STR << "+HEARTHEXENA:ON\r\n";
				else
					ss << AT_OK_STR << "+HEARTHEXENA:OFF\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTHEXENA" , item ) );  
}

void atInst :: init_heart_hexb()
{
	stAtHash  item("AT\\+HEARTHEXENB(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket B heart package HEX switch status." ,
                   "AT+HEARTHEXENB[?]<RET> Get status;\nAT+HEARTHEXENB=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ].find("ON") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock2/heart/hex" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find("OFF") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock2/heart/hex" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
				bool en = false;
				ptvar->GetValue( "/net/socket/sock2/heart/hex" , en );
				if( en )
					ss << AT_OK_STR << "+HEARTHEXENB:ON\r\n";
				else
					ss << AT_OK_STR << "+HEARTHEXENB:OFF\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTHEXENB" , item ) );    
}

void atInst :: init_upgrade()
{/*
	stAtHash  item("AT\\+UPGRADE=((\\d+(\\.\\d+){3}),){0,1}\\w+\\r" ,
                   "trig fireware upgrade." ,
                   "AT+UPGRADE=<PASSWORD> upgrade to latest version;AT+UPGRADE=<VERSION>,<PASSWORD> upgrade to specified version." );
    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		ptvar->GetValue( "/upgrade_pswd" , str );
		if( params.size() == 2 ){         // 指定了版本和密码
			if( str == params[ 1 ] ){     // 执行升级
				devManage * pDevM = GetOrCreateDevManager();
				if( pDevM ){
					pDevM->RunUpgrade( params[ 0 ] );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_UPGRADE_ENGINE << "\r\n";
					str = AT_OK_STR;
				}
			}else{                        // 密码错误
				ss << "\r\n+ERR:" << ERR_BAD_UPGRADE_PASWD << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() == 1 ){   // 只提供了密码
			if( str == params[ 1 ] ){     // 执行升级
				devManage * pDevM = GetOrCreateDevManager();
				if( pDevM ){
					pDevM->RunUpgrade( "" );
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_UPGRADE_PASWD << "\r\n";
					str = std::move( ss.str() );                        
				}
			}else{                        // 密码错误
				ss << "\r\n+ERR:" << ERR_BAD_UPGRADE_PASWD << "\r\n";
				str = std::move( ss.str() );
			}
		}else{                            // 指令格式错误
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+UPGRADE" , item ) );  
	*/
}

void atInst :: init_uppswd()
{
	stAtHash  item("AT\\+UPGPSWD=\\w+,\\w+\\r" ,
                   "modify upgrade password" ,
                   "AT+UPGPSWD=<OLD>,<NEW>" );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		ptvar->GetValue( "/upgrade_pswd" , str );
		if( params.size() == 2 ){
			if( params[ 0 ] == str ){
				ptvar->SetValue( "/upgrade_pswd" , params[ 1 ] );
				str = AT_OK_STR;
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_UPGRADE_PASWD << "\r\n";
				str = std::move( ss.str() );                    
			}
		}else{
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );                
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+UPGPSWD" , item ) );  
}

void atInst :: init_heart_hexc()
{
	stAtHash  item("AT\\+HEARTHEXENC(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket C heart package HEX switch status." ,
                   "AT+HEARTHEXENC[?]<RET> Get status;\nAT+HEARTHEXENC=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
		if( params.size() == 1 ){
			if( params[ 0 ].find("ON") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock3/heart/hex" , true );
				str = AT_OK_STR;
			}else if( params[ 0 ].find("OFF") != std::string::npos ){
				ptvar->SetValue( "/net/socket/sock3/heart/hex" , false );
				str = AT_OK_STR;
			}else{// 语法错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else if( params.size() > 1 ){
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}else{// 查询
			bool en = false;
			ptvar->GetValue( "/net/socket/sock3/heart/hex" , en );
			if( en )
				ss << AT_OK_STR << "+HEARTHEXENC:ON\r\n";
			else
				ss << AT_OK_STR << "+HEARTHEXENC:OFF\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};
    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTHEXENC" , item ) );  
}
void atInst :: init_heart_hexd()
{
	stAtHash  item("AT\\+HEARTHEXEND(\\?|=(ON|OFF)){0,1}\\r" ,
                   "Get or set socket D heart package HEX switch status." ,
                   "AT+HEARTHEXEND[?]<RET> Get status;\nAT+HEARTHEXEND=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		if( ptvar ){
			if( params.size() == 1 ){
				if( params[ 0 ].find("ON") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock4/heart/hex" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find("OFF") != std::string::npos ){
					ptvar->SetValue( "/net/socket/sock4/heart/hex" , false );
					str = AT_OK_STR;
				}else{// 语法错误
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{// 查询
				bool en = false;
				ptvar->GetValue( "/net/socket/sock4/heart/hex" , en );
				if( en )
					ss << AT_OK_STR << "+HEARTHEXEND:ON\r\n";
				else
					ss << AT_OK_STR << "+HEARTHEXEND:OFF\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+HEARTHEXEND" , item ) );  
}
void atInst :: init_gpsen()
{
	stAtHash  item("AT\\+GPSEN(\\?|\\=(ON|OFF)){0,1}\\r" ,
                   "Get or set GPS enable switch status." ,
                   "AT+GPSEN[?]<RET> Get status;\nAT+GPSEN=(ON|OFF) set status." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			
		if( ptvar ){
			if( params.size() == 1 ){ // 设置
				if( params[ 0 ] == "ON"){
					ptvar->SetValue( "/gps/enable" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ] == "OFF"){
					ptvar->SetValue( "/gps/enable" , false );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else if(params.size() > 1 ){ // AT指令格式错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				bool data;
				ptvar->GetValue( "/gps/enable" , data );
				ss << AT_OK_STR << "+GPSEN:" << ( data == true ? "ON" : "OFF" ) << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+GPSEN" , item ) );
}
void atInst :: init_agps()
{
	stAtHash  item("AT\\+AGPS(\\?|(\\=(ON|OFF),(MSAssis|MSBase))){0,1}\\r" ,
                   "Set or Get AGPS paramters" ,
                   "AT+AGPS[?] Get AGPS parameter;AT+AGPS=ON|OFF,MSBase|MSAssis Set parameter." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			
		if( ptvar ){
			if( params.size() == 2 ){
				// 设置允许参数
				if( params[ 0 ] == "ON" ){
					ptvar->SetValue( "/gps/agps/enable" , true );
				}else if( params[ 0 ] == "OFF" ){
					ptvar->SetValue( "/gps/agps/enable" , false );
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
					response( at , str );
					return;
				}
				// 设置方式参数
				if( params[ 1 ] == "MSBase"){
					ptvar->SetValue( "/gps/agps/mtd" , std::string("MSBase" ));
				}else if( params[ 1 ] == "MSAssis"){
					ptvar->SetValue( "/gps/agps/mtd" , std::string( "MSAssis") );
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
					response( at , str );
					return;
				}

				str = AT_OK_STR;
			}else if( params.size() > 2 || params.size() == 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = ss.str();
			}else{
				bool data;

				ptvar->GetValue( "/gps/agps/enable" , data );
				ptvar->GetValue( "/gps/agps/mtd" , str );
				ss << AT_OK_STR << "+AGPS:" << ( data == true ? "ON" : "OFF") << "," << str << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+AGPS" , item ) );
}

void atInst :: init_gpsfreq()
{
	stAtHash  item("AT\\+GPSFREQ(\\?|=\\d+){0,1}\\r" ,
                   "Set or Get GPS location frequency." ,
                   "AT+GPSFREQ[?] Get location frequency; AT+GPSFREQ=<DIGIT> Set location frequency" );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 1 ){
				int data;
				ss << params[ 0 ];
				ss >> data;

				ptvar->SetValue("/gps/updateInterval" , data );
				str = AT_OK_STR;
			}else if( params.size() > 1 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				int data;
				ptvar->GetValue( "/gps/updateInterval" , data );
				ss << AT_OK_STR << "+GPSFREQ:" << data << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

   	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+GPSFREQ" , item ) );
}

void atInst :: init_gpssv()
{
	stAtHash  item("AT\\+GPSSV\\?{0,1}\\r" ,
                   "Get GPS satellites infomation." ,
                   "AT+GPSSV[?]" );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			
		if( ptvar ){
			if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				gpsCtrl * gps = CreateGPS();
				if( gps ){
					ss << AT_OK_STR << "+GPSSV:" << gps->SvCount() << "\r\n";
				}else{
					ss << "\r\n+ERR:" << ERR_GPS_NOT_INIT << " GPS not is initialized.\r\n";
				}

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+GPSSV" , item ) );
}
void atInst :: init_gpsdat()
{
	stAtHash  item("AT\\+GPSDAT\\?{0,1}\\r" ,
                   "Get GPS Location data" ,
                   "AT+GPSDAT[?]" );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			
		if( ptvar ){
			if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				gpsCtrl * gps = CreateGPS();
				if( gps ){
					double lat , longt , al , acc;
					gps->Location( lat , longt , al , acc );
					ss << AT_OK_STR << "+GPSDAT:" << lat << "," << longt << "," << al << "," << acc << "\r\n";
				}else{
					ss << "\r\n+ERR:" << ERR_GPS_NOT_INIT << "\r\n";
				}

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};

    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+GPSDAT" , item ) );
}

void atInst :: init_gpsspeed()
{
	stAtHash  item("AT\\+GPSSPEED\\?{0,1}\\r" ,
                   "Get GPS move speed data." ,
                   "AT+GPSSPEED[?]" );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			
		if( ptvar ){
			if( params.size() > 0 ){
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}else{
				float s , h;
				gpsCtrl * gps = CreateGPS();
				if( gps ){
					gps->Speed( s , h );
					ss << AT_OK_STR << "+GPSSPEED:" << s << "," << h << "\r\n";
				}else{
					ss << "\r\n+ERR:" << ERR_GPS_NOT_INIT << "\r\n";
				}

				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};

	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+GPSSPEED" , item ) );
}


#if ENABLE_WIFI == 1 
void atInst :: init_wifien()
{
	stAtHash  item("AT\\+WIFIEN(\\?|\\=(ON|OFF)){0,1}\\r" ,
			"Get Or set WiFi switch status." ,
			"AT+WIFIEN[?] Get wifi status" );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
		if( params.size( ) == 0 ){  // 读取状态
			bool rst = false;
			ptvar->GetValue( "/wifi/enable" , rst );

			ss << AT_OK_STR << "+WIFIEN:" << ( rst ? "ON" : "OFF" ) << "\r\n";
			str = std::move( ss.str() );
		}
		else if( params.size() == 1 ){ // 设置状态
			ptvar->SetValue("/wifi/enable", params[0].find("ON") != std::string::npos ? true : false); //== "ON" ? true : false );
			str = AT_OK_STR;
			if (params[0].find("ON") != std::string::npos)//( params[ 0 ] == "ON")
			{
				ql_wifi_enable();
				__show_line_1("%s%s%s", TBLUE, "Wifi module ON.", TNORMAL);
			}
			else
			{
				ql_wifi_disable();
				__show_line_1("%s%s%s", TBLUE, "Wifi module OFF.", TNORMAL);
			}
		}else{  // 语法错误=ON
			ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
			str = std::move( ss.str() );
		}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+WIFIEN" , item ) );
}
void atInst :: init_wifi()
{
    	stAtHash  item("AT\\+WIFI(\\?|=(2|5)\\,\\w+\\,\\w{6,10}){0,1}\\r" ,
                   "Get GPS move speed data." ,
                   "AT+GPSSPEED[?]" );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 3 ){ // 设置参数
				ptvar->SetValue("/wifi/band" , params[ 0 ]);
				ptvar->SetValue( "/wifi/ssid" , params[ 1 ] );
				ptvar->SetValue( "/wifi/passwd" , params[ 2 ] );

				ql_wifi_ap_auth_s auth;
				ql_wifi_work_mode_set(QL_WIFI_WORK_MODE_AP0);
				ql_wifi_ap_ssid_set(QL_WIFI_AP_INDEX_AP0, ( char *)( params[ 1 ].c_str() ) );

				if( params[ 0 ] == "2" )
					ql_wifi_ap_mode_set(QL_WIFI_AP_INDEX_AP0, QL_WIFI_MODE_80211BGN);
				else if( params[ 0 ] == "5" )
					ql_wifi_ap_mode_set(QL_WIFI_AP_INDEX_AP0, QL_WIFI_MODE_80211AC);
				else
					ql_wifi_ap_mode_set(QL_WIFI_AP_INDEX_AP0, QL_WIFI_MODE_80211BGN);

				ql_wifi_ap_bandwidth_set(QL_WIFI_AP_INDEX_AP0, QL_WIFI_BANDWIDTH_HT40);
				ql_wifi_ap_channel_set(QL_WIFI_AP_INDEX_AP0, 11);

				auth.auth = QL_WIFI_AUTH_WPA_PSK;
				auth.wpa_psk.pairwise = QL_WIFI_AUTH_WPA_PAIRWISE_AUTO;
				auth.wpa_psk.group_rekey = 3600;                        /* one hour */
				strcpy(auth.wpa_psk.passwd, params[ 2 ].c_str() );
				ql_wifi_ap_auth_set(QL_WIFI_AP_INDEX_AP0, &auth);
				str = AT_OK_STR;
			}else if( params.size() == 0 ){ // 查询结果
				std::string ssid , pswd;
				ptvar->GetValue( "/wifi/ssid" , ssid );
				ptvar->GetValue( "/wifi/passwd" , pswd );

				ss << AT_OK_STR << "+WIFI:" << ssid << "," << pswd << "\r\n";
				str = std::move( ss.str() );
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};
    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+WIFI" , item ) );
}

void atInst :: init_wificln()
{
    	stAtHash  item("AT\\+WIFICLN(\\?){0,1}\\r" ,
                   "Get WIFI Client Infomation." ,
                   "AT+WIFICLN，query wifi client list." );

    	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 0 ){ // 查询结果
				std::string   band , ssid , pswd;
				ptvar->GetValue( "wifi/band" , band );
				ptvar->GetValue( "/wifi/ssid" , ssid );
				ptvar->GetValue( "/wifi/passwd" , pswd );
				ss << AT_OK_STR << "+WIFICLN:" << band << "," << ssid << "," << pswd << "\r\n";
				str = std::move( ss.str() );
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+WIFICLN" , item ) );
}
#endif
#if ENABLE_PHY == 1 
void atInst :: init_phyen()
{
	stAtHash  item("AT\\+PHYEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Enable or disable phy." ,
			"AT+PHYEN[?] Query setting; AT+PHYEN=ON|OFF, enable or disable phy." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 0 ){ // 查询结果
				bool en;
				ptvar->GetValue( "/phyen" , en );
				ss << AT_OK_STR << "+PHYEN:" << ( en == true ? "ON": "OFF") << "\r\n";
				str = std::move( ss.str() );
			}else if( params.size() == 1 ){
				if( params[ 0 ].find( "ON" ) != std::string::npos ){
					ptvar->SetValue( "/phyen" , true );
					str = AT_OK_STR;
				}else if( params[ 0 ].find( "OFF" ) != std::string::npos ){
					ptvar->SetValue( "/phyen" , false );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+PHYEN" , item ) );
}
#endif
#if ENABLE_WIFI == 1 || ENABLE_PHY == 1
TiXmlElement * atInst :: getIPNode( TiXmlElement * root )
{
	TiXmlElement * ret = root;
	if( ret != nullptr ){
		__show_line_2();
		ret = ret->FirstChildElement("MobileAPCfg");

		if( ret != nullptr ){
			__show_line_2();
			ret = ret->FirstChildElement( "MobileAPLanCfg" );

			if( ret != nullptr ){
				ret = ret->FirstChildElement( "APIPAddr" );
			}
		}
	}

	return ret;
}

void atInst :: init_rootPswd()
{
	stAtHash  item("AT\\+ROOTPSWD(\\?|=\\w{6~16},\\w{6,16}\\r" ,
			"Enable or disable firewall." ,
			"AT+ROOTPSWD[?] Query setting; AT+ROOTPSWD=ON|OFF, enable or disable firewall." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 2 ){
				ptvar -> GetValue( "/firewall/password" , str );
				if( params[ 0 ].find( str ) != std::string::npos ){ // 
					ptvar->SetValue( "/firewall/password" , params[ 1 ] );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_ROOT_PSWD << "\r\n";
						str = std::move( ss.str() );
				}
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
						str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+ROOTPSWD" , item ) );
}

void atInst :: init_firewall()
{
	stAtHash  item("AT\\+FIREN(\\?|=\\w{6,16},(ON|OFF)){0,1}\\r" ,
			"Enable or disable firewall." ,
			"AT+FIREN[?] Query setting; AT+FIREN=ON|OFF, enable or disable firewall." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
		
			ptvar->GetValue( "/firewall/password" , str );

			if( params.size() > 0 && str.find( params[ 0 ] ) == std::string::npos ){
				ss << "\r\n+ERR:" << ERR_BAD_ROOT_PSWD << "\r\n";
				str = std::move( ss.str() );
				response( at , str );
				return;
			}
		
			m_root_status = true;

			if( params.size() == 0 ){ // 查询结果
				bool en;
				ptvar->GetValue( "/firewall/enable" , en );
				__show_line_1("%s /firewall/enable=%d%s" , TYELLOW , en , TNORMAL);
				ss << AT_OK_STR << "+FIREN:" << ( en == true ? "ON": "OFF") << "\r\n";
				str = std::move( ss.str() );
			}else if( params.size() == 2 ){
				if( params[ 1 ].find( "ON" ) != std::string::npos ){ // 
					ptvar->SetValue( "/firewall/enable" , true );
					system( "iptables -P INPUT ACCEPT");          // 打开入站链
					system( "iptables -P OUTPUT ACCEPT");         // 打开出站链
					system( "iptables -P FORWARD DROP" );         // 关闭路由链
					system( "iptables -F" );

					system( "iptables -A FORWARD -p udp --sport 53 -j ACCEPT" );
					system( "iptables -A FORWARD -p udp --dport 53 -j ACCEPT" );
					do_firewall_set( "117.78.33.204" );           // 打开管理平台
					
					str = AT_OK_STR;
				}else if( params[ 1 ].find( "OFF" ) != std::string::npos ){
					ptvar->SetValue( "/firewall/enable" , false );
					system( "iptables -P FORWARD ACCEPT" );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
					str = std::move( ss.str() );
				}
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
    	};
    	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+FIREN" , item ) );
}

std::string atInst :: do_firewall_set( const std::string & ip  )
{
	std::string str , cmd;
	cmd = "iptables -A FORWARD -s " + ip + " -j ACCEPT";
	system( cmd.c_str() );
	cmd = "iptables -A FORWARD -d " + ip + " -j ACCEPT";
	system( cmd.c_str() );

	str = AT_OK_STR;
	return str;
}
void atInst :: init_firelist()
{
	stAtHash  item("AT\\+FIRERUL(\\?|=\\d{1,3}(\\.\\d{1,3}){3}){0,1}\\r" ,
			"Set or query router out rules." ,
			"AT+FIRERUL[?] Query setting; AT+FIRERUL=<IP> Set route dest Server IP. " );
	// AT+FIRERUL=TCP,117.78.33.204,10000 ，允许访问目标
	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 0 ){ // 查询结果
				ArrayString  rst;
				get_firewall_out( rst );
				ss << "\r\nOK\r\n+FIRERUL:"; 
				for( size_t i = 0; i < rst.size(); i ++ ){
					ss << rst[ i ] << "\r\n";
				}
				str = std::move( ss.str() );
			}else if( params.size() == 1 ){
				if( m_root_status == false ){
				ss << "\r\n+ERR:" << ERR_BAD_ROOT_STATUS << "";
				str = std::move( ss.str() );
				response( at , str );
				return;
				}
			
				str = do_firewall_set( params[ 0 ] );
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+FIRERUL" , item ) );
}

void atInst :: init_firesave()
{
	stAtHash  item("AT\\+FIRESAVE\\r" ,
			"Save firewall setting." ,
			"AT+FIRESAVE Save Firewall setting." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;

		if( m_root_status == false ){
			ss << "\r\n+ERR:" << ERR_BAD_ROOT_STATUS << "";
			str = std::move( ss.str() );
			response( at , str );
			return;
		}

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			system( "iptables-save > /data/sndtu/firewall.rules" );
			ptvar->Save( "/data/sndtu/config.xml" );
			str = "Device will reboot.";
			sync();
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );

		std::this_thread::sleep_for( std::chrono::seconds( 5 ));
		reboot( RB_AUTOBOOT );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+FIRESAVE" , item ) );
}

void atInst :: get_firewall_mac( ArrayString & rst )
{
	FILE * fp = popen( "iptables -L | grep MAC" , "r");

	char data[ 200 ];
	memset( data , 0 , 200 );
	size_t len = 0;
	if( fp ){
		while( getline( (char **)&data , &len , fp ) != -1 ){
			rst.push_back( data );
		}
		pclose( fp );

		std::regex reg( "\\d{2}(:\\d{2}){5}" );
		std::smatch  m;
		std::string tmp_str;
		for( size_t i = 0; i < rst.size(); i ++ ){
			tmp_str = rst[ i ];
			if( std::regex_search( tmp_str , m , reg ) == true ){
				rst[ i ] = tmp_str;
			}
		}
	}
}

void atInst :: firewall_filter_port( ArrayString& rst )
{
	ArrayString  tmpA;
	std::regex   reg1( "(?:\\s\\w(\\w|\\s)+:)\\d{1,5}" ),
			reg2( "\\s\\w(\\w|\\s)+:\\d{1,5}" );
	std::string port ;
	std::smatch m;

	for( auto a : rst ){
		if( std::regex_match( a , m , reg1 ) == true ){
			port = std::move( m[ 0 ] );
			port = std::string( "," ) + port + "$1";

			a = std::regex_replace( a , reg2 , port );

			tmpA.push_back( a );
		}
	}

	if( tmpA.size() > 0 ) rst = std::move( tmpA );
}

void atInst :: firewall_out_filter_forward( ArrayString& rst )
{
	ArrayString  tmpArray;
	size_t       forward_pos = 0;
	__show_line_1( "%s [%d] %s%s" , TGREEN , __LINE__ , TNORMAL , __PRETTY_FUNCTION__ );
	for( size_t i = 0; i < rst.size(); i ++ ){
		// 过滤INPUT链
		if( rst[ i ].find( "Chain FORWARD" ) != std::string::npos && forward_pos == 0 ){
			continue;
		}else if( forward_pos == 0 ){
			forward_pos = i + 5;
			i = forward_pos;
		}
		//__show_line_1( "%s [forward list: %s] %s%s" , TGREEN , rst[ i ].c_str() , TNORMAL , __PRETTY_FUNCTION__ );
		if( rst[ i ].find( "Chain OUTPUT" ) != std::string::npos ){  // 过滤OUTPUT链
			break;
		}else{ 
			tmpArray.push_back( rst[ i ] );
			//__show_line_1( "%s [forward list: %s] %s%s" , TGREEN , rst[ i ].c_str() , TNORMAL , __PRETTY_FUNCTION__ );
		}
	}

	rst = std::move( tmpArray );
}

void atInst :: get_firewall_out( ArrayString& rst )
{
	FILE * fp = popen( "iptables -L -n" , "r");
	__show_line_1( "%s [%d] %s%s" , TGREEN , __LINE__ , TNORMAL , __PRETTY_FUNCTION__ );
	char *data = nullptr;
	size_t len = 0;
	if( fp ){
		while( getline( (char **)&data , &len , fp ) != -1 ){
			rst.push_back( data );
			if( data ){
				free( data );
				data = nullptr;
			}
		}
		pclose( fp );

		firewall_out_filter_forward( rst );            // 摘出路由链

		ArrayString tmpA;
		std::smatch sm;
		std::regex  reg( "\\d{1,3}(\\.\\d{1,3}){3}" );
		for( size_t i = 0; i < rst.size(); i ++ ){
			std::string str = rst[ i ];
			if( std::regex_search( str , sm , reg ) == true ){
				str = sm[ 0 ];
				if( str == "0.0.0.0" ){continue;}
				if( str == "117.78.33.204" ){continue;}
				__show_line_1( "%s [ str = %s ] %s%s" , TGREEN , str.c_str() , TNORMAL , __PRETTY_FUNCTION__ );
				tmpA.push_back( str );
			}
		}

		rst = std::move( tmpA );
	}
}

void atInst :: init_firemac()
{
	stAtHash  item("AT\\+FIREMAC(\\?|=(ADD|DEL),[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}){0,1}\\r" ,
			"Add white list." ,
			"AT+FIREMAC[?] Query setting; AT+FIREMAC=<ADD|DEL>,<MAC ADDRESS>, Add or delete white list." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		if( true ){   // 控制MAC暂时不能用，所以这里直接返回
			return;
		}

		std::string              str;
		std::stringstream        ss;
		if( m_root_status == false ){
			ss << "\r\n+ERR:" << ERR_BAD_ROOT_STATUS << "";
			str = std::move( ss.str() );
			response( at , str );
			return;
		}

		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 0 ){ // 查询结果
				ArrayString a_str;
				get_firewall_mac( a_str );
				ss << "\r\nOK\r\n+FIREMAC: ";
				
				for( auto a : a_str ){ ss << a << ",";  }

				str = std::move( ss.str() );
				str = str.substr( 0 , str.length() - 1 );
				str += "\r\n";
			}else if( params.size() == 2 ){
				if( params[ 0 ].find( "ADD" ) != std::string::npos ){  // 𣸸加规则
					std::string str1 = "iptables -A INPUT -m mac --mac-source " + params[ 1 ] + " -j ACCEPT",
					system( str1.c_str() );

				}else if( params[ 0 ].find( "DEL" ) != std::string::npos ){ // 删除规则
					std::string str1 = "iptables -D INPUT -m mac --mac-source " + params[ 1 ] + " -j ACCEPT",
					system( str1.c_str() );
				}

				str = AT_OK_STR;
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+FIREMAC" , item ) );
}

TiXmlElement * atInst :: getStart( TiXmlElement * root )
{
	TiXmlElement * ret = root;
	if( ret != nullptr ){

		ret = ret->FirstChildElement( "MobileAPCfg" );
		if( ret != nullptr ){
			ret = ret->FirstChildElement( "MobileAPLanCfg" );
		if( ret != nullptr ){

			ret = ret->FirstChildElement( "DHCPCfg" );
			if( ret != nullptr ){

				ret = ret->FirstChildElement("StartIP");
			}
		}
		}
	}
	
	return ret;
}

TiXmlElement * atInst :: getStop( TiXmlElement * root )
{
	TiXmlElement * ret = root;
	__show_line_2();
	if( ret != nullptr ){
		__show_line_2();
		ret = ret->FirstChildElement( "MobileAPCfg" );
		if( ret != nullptr ){
			ret = ret -> FirstChildElement( "MobileAPLanCfg" );
			if( ret != nullptr ){
				__show_line_2();
				ret = ret -> FirstChildElement( "DHCPCfg" );
				if( ret != nullptr ){
					__show_line_2();
					ret = ret -> FirstChildElement("EndIP");
				}
			}//
		}// if( ret != nullptr )
	}
	
	return ret;
}

TiXmlElement * atInst :: getMask( TiXmlElement * root )
{
	TiXmlElement * ret = root;
	__show_line_2();
	if( ret != nullptr ){
		__show_line_2();
		ret = ret->FirstChildElement( "MobileAPCfg" );
		if( ret != nullptr ){
			ret = ret -> FirstChildElement( "MobileAPLanCfg" );
			if( ret != nullptr ){
				__show_line_2();
				ret = ret -> FirstChildElement( "SubNetMask" );
			}
		}
	}
	
	return ret;
}
int atInst :: update_mobileap_cfg(  const std::string& ip , 
                                    const std::string& start , 
                                    const std::string& end , 
                                    const std::string& mask )
{
	int ret = 0;
	TiXmlDocument doc( "/etc/mobileap_cfg.xml" );
	doc.LoadFile();
	TiXmlElement * root = doc.RootElement();
	if( root == nullptr ) return -10;
	if( doc.Error() == false ){
		// 更新IP
		TiXmlElement * ele = getIPNode( root );
		if( ele != nullptr ){
			TiXmlText * txt = (TiXmlText*)ele->FirstChild();
			if( txt )
				txt->SetValue( ip );
			else return -2;
		}else return -1;
		// 更新起始地址
		ele = getStart( root );
		if( ele != nullptr ){
			TiXmlText * txt = (TiXmlText * )ele -> FirstChild();
			if( txt )
				txt->SetValue( start );
			else return -3;
		}else return -4;
		// 更新结束地址
		ele = getStop( root );
		if( ele != nullptr ){
			TiXmlText * txt = (TiXmlText * )ele->FirstChild();
			if( txt ) txt->SetValue( end );
			else return -5;
		}else return -6;
		// 更新地址掩码
		ele = getMask( root );
		if( ele != nullptr ){
			TiXmlText * txt = (TiXmlText *)ele->FirstChild();
			if( txt ) txt->SetValue( mask );
			else return -7;
		}else return -8;

		if( doc.SaveFile() ) ret = 0;
		else ret = -11;
	}else{
		ret = -9;
	}
	return ret;
}

std::string atInst :: set_lan_params( std::shared_ptr<CSysVar> ptvar , const std::string& ip , const std::string& start , const std::string& stop , const std::string& mask )
{
	std::string ret ;
	// 更改DTU设置文件
	if( ptvar ){
		ptvar->SetValue( "/LAN/APID" , ip );
		ptvar->SetValue( "/LAN/poolStart" , start );
		ptvar->SetValue( "/LAN/poolStop" , stop );
		ptvar->SetValue( "/LAN/netMask" , mask );
	}
	// 更改mobileap_cfg.xml . 注意这里操作完成后会立即修改文件，如果后续没有修改
	// DTU的配置文件将会造成数据不统一的情况。
	int err = update_mobileap_cfg( ip , start , stop , mask );
	__show_line_1( "%s update system lan param err = %d%s" , TRED , err , TNORMAL );
	if( err == 0 )
		ret = AT_OK_STR;
	else{
		std::stringstream ss;
		ss << "+ERR:" << ERR_SYS << "\r\n";
		ret = std::move( ss.str() );
	}

	return ret;
}

void atInst :: query_lan_params( std::shared_ptr<CSysVar> ptvar , std::string& rst )
{
	std::string ip , start , stop , mask;
	if( ptvar ){
		ptvar->GetValue( "/LAN/APID" , ip );
		ptvar->GetValue( "/LAN/poolStart" , start );
		ptvar->GetValue( "/LAN/poolStop" , stop );
		ptvar->GetValue( "/LAN/netMask" , mask );

		std::stringstream ss;
		ss << AT_OK_STR << "+LAN:" << ip << "," << start << "," << stop << "," << mask << "\r\n";
		rst = ss.str() ;
	}
}

void atInst :: init_lan()
{
	stAtHash  item("AT\\+LAN(((\\=(\\d{1,3}(\\.\\d{1,3}){3}))(\\,\\d{1,3}(\\.\\d{1,3}){3}){3})?|(\\?{0,1}))\\r{0,1}" ,
			"set or query lan parameters." ,
			"AT+LAN[?] Query setting; AT+LAN=<IP>,<START>,<END>,<MASK> Set parameters." );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();

		if( ptvar ){
			if( params.size() == 0 ){ // 查询结果
				std::string str1;
				query_lan_params( ptvar , str1 );
				ss << AT_OK_STR << "+LAN:" << str1 << "\r\n";
				str = std::move( ss.str() );
			}else if( params.size() == 4 ){
				str = set_lan_params( ptvar , params[ 0 ] , params[ 1 ] , params[ 2 ] , params[ 3 ] );
				if( str.find("OK") != std::string::npos ){
					ptvar->Save("/data/sndtu/config.xml");
					str = AT_OK_STR + "Device will restart.\r\n";
					if( m_at_type == atInst :: at_serial ){
						backward(  ptList[ 0 ]->rbegin() , str.length() , str.c_str() , OK );
					}
					else if( m_at_type == atInst :: at_net ){   
						forward( ptList[ 0 ]->begin() , str.length() , str.c_str() , OK );
					}
					sync();
					reboot( RB_AUTOBOOT );
				}
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+LAN" , item ) );
}
#endif
#if ENABLE_MODBUS == 1 
#include "modbus_setting.hpp"

void atInst :: init_modbus_en()
{
	stAtHash  item("AT\\+MBEN(\\?|=(ON|OFF)){0,1}\\r" ,
			"Query or set modbus enable." ,
			"AT+MBEN[?]Query enable switch; AT+MBEN=ON|OFF<RET> Set enable switch" );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		bool en = false;
		if( ptvar ){
			if( params.size() == 0 ){ // 查询结果
				ptvar->GetValue("/modbus/enable" , en );
				ss << AT_OK_STR << "+MBEN:" << (en ? "ON" : "OFF") << "\r\n";
				str = std::move( ss.str() );
			}else if( params.size() == 1 ){
				str = params[ 0 ] ;
				if( str.find( "ON" ) != std::string::npos ){
					ptvar->SetValue( "/modbus/enable" , true );
					str = AT_OK_STR;
				}else if( str.find( "OFF") != std::string::npos ){
					ptvar->SetValue( "/modbus/enable" , false );
					str = AT_OK_STR;
				}else{
					ss << "\r\n+ERR:" << ERR_BAD_ENUM_VALUE << "\r\n";
					str = std::move( ss.str() ); 
				}
			}else{
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MBEN" , item ) );
}

void atInst :: init_mbadd()
{
    /**
     * @note 模块的MODBUS-RTU采集功能仅仅支持0x01, 0x02,0x03,0x04四种采集指令，对于其他的采集
     * 指令将会匹配失败。 
     */
	stAtHash  item("AT\\+MBADD=[1234](,\\d+){4}\\r" ,
			"Add modbus read mission." ,
			"AT+MBADD=<command> ,<site>,<start register>,<count>,<interval><RET>" );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		__show_line_1( "%sAT COMMAND = %s%s" , TYELLOW , at.c_str() , TNORMAL );
		if( ptvar ){
			if( params.size() == 5 ){ // 
				__show_line_2();
				int opt ,site , reg , count , intval;
				ss << params[ 0 ];    ss >> opt;      ss.str( "" ); ss.clear(); 
				ss << params[ 1 ];    ss >> site;     ss.str( "" ); ss.clear();
				ss << params[ 2 ];    ss >> reg;      ss.str( "" ); ss.clear();
				ss << params[ 3 ];    ss >> count;    ss.str( "" ); ss.clear();
				ss << params[ 4 ];    ss >> intval;   ss.str( "" ); ss.clear();
				ptvar->GetValue( "/modbus/path" , str );
				try{
					ModbusSetting  doc(str);
					doc.Mission( opt , site , reg , count , intval );
					doc.Save( str );
					str = AT_OK_STR;
				}catch( ModbusSetting::err_code e ){
					__show_line_1( "%s%s%s" , TRED , "Operate modbus configure file fail." , TNORMAL );
					abort();
				}catch( ... ){
					__show_line_1( "%s%s%s" , TRED , "Unknow error" , TNORMAL );
					abort();
				}
			}else{ // 错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		__show_line_2();
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MBADD" , item ) );
}

void atInst :: init_mbl()
{
	stAtHash  item("AT\\+MBL(\\?){0,1}\\r" ,
			"list modbus mission." ,
			"AT+MBL[?]Query modbus mission list;" );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string              str;
		std::stringstream        ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
		char                     tmp_data[ 100 ];
		if( ptvar ){
			if( params.size() == 0 ){ // 
				std::string file;
				ptvar->GetValue( "/modbus/path" , file );
				if( !file.empty() ){
					try{
						if( access( file.c_str() , F_OK ) == 0 ){
							ModbusSetting               doc( file );
							ModbusSetting::ModMission   missions = doc.Mission();

							ss << AT_OK_STR << missions.size() << "\r\n";
							str = ss.str();
							
							for( size_t i = 0; i < missions.size() ; i ++ ){
								sprintf( tmp_data , "%d,%d,%d,%d,%ld\r\n" , 
								missions[ i ].opt ,             missions[ i ].site , 
								missions[ i ].start_reg ,       missions[ i ].count ,
								missions[ i ].interval );
								str += tmp_data;
							}
						}else{ // 文件不存在
							ss << "\r\n+ERR:" << ERR_MODBUS_PATH << "\r\n";
							str = std::move( ss.str() );
						}
					}catch( ModbusSetting::err_code e ){ // modbus模块操作错误
						ss << "\r\n+ERR:" << ERR_MODBUS_OPERATION << "\r\n";
						str = std::move( ss.str() );
					}
				}else{ // 路径空
					ss << "\r\n+ERR:" << ERR_MODBUS_PATH_EMPTY << "\r\n";
					str = std::move( ss.str() );
				}
			}else{ // 错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{ // 系统变量模块出现错误
			ss.clear(); ss.str();
			ss << "\r\n+ERR:" << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MBL" , item ) );
}

void atInst :: init_mbdel()
{
	stAtHash  item("AT\\+MBDEL=\\d+\\r" ,
			"Remove modbus mission." ,
			"AT+MBDEL=<ID><RET> Remove modbus mission by ID;" );

	item.fun = [ this ](const std::string& at ,const ArrayString& params ){
		std::string                     str;
		std::stringstream               ss;
		std::shared_ptr<CSysVar> ptvar = GetOrCreateSysVar();
			
		if( ptvar ){
			if( params.size() == 1 ){ // 
				ptvar->GetValue( "/modbus/path" , str );
				if( !str.empty() ){
					try{
						ModbusSetting    doc( str );
						ss << params[ 0 ];
						int id = -1;
						ss >> id;
						doc.Del( id );
						doc.Save( str );
							
						str = AT_OK_STR;
					}catch( ModbusSetting::err_code e ){
						ss << "\r\n+ERR:" << ERR_MODBUS_OPERATION << "\r\n";
						str = std::move( ss.str() );
					}
				}else{  // 路径空
					ss << "\r\n+ERR:" << ERR_MODBUS_PATH_EMPTY << "\r\n";
					str = std::move( ss.str() );
				}
			}else{ // 错误
				ss << "\r\n+ERR:" << ERR_BAD_GRAMMA << "\r\n";
				str = std::move( ss.str() );
			}
		}else{
			ss.clear(); ss.str();
			ss << "\r\n+ERR:    " << ERR_CAN_NOT_SYS_VAR << "\r\n";
			str = std::move( ss.str() );
		}
		response( at , str );
	};
	m_at_hash.insert( std::pair< std::string , stAtHash>( "AT+MBDEL" , item ) );
}
#endif

bool IsInSerialAT()
{
	bool ret = false;
	if( atCom::ptSerialAT == nullptr ){
		std::cout << "AT module is not initialized." << std::endl;
		abort();
	}else{
		ret = ( atCom::ptSerialAT->Status() != atInst :: status:: TRANS );
	}

	return ret;
}

bool IsATHandShake()
{
	bool ret = false;
	if( atCom :: ptSerialAT == nullptr ){
		std::cout << "AT module is not initialized." << std::endl;
		abort();        
	}else{
		ret = ( atCom::ptSerialAT->Status() == atInst::status:: HANDSHAKEING) || 
		( atCom::ptSerialAT->Status() == atInst::status:: HANDSHAKEING_2 );
	}

	return ret;
}
